Skip to content

Commit

Permalink
jj
Browse files Browse the repository at this point in the history
  • Loading branch information
gzshawnliang committed Jan 25, 2019
1 parent 77144f4 commit 7ec7c57
Show file tree
Hide file tree
Showing 5 changed files with 22,530 additions and 33 deletions.
28 changes: 18 additions & 10 deletions myCpps/RMQWithShifts_UVA12299.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,24 @@ ofstream fout("RMQWithShifts_UVA12299.out");
class fenwickTree
{
private:

vector<int> a;
vector<int> s;

vector<int> c;

int lowbit(int x)
{
return x & (-x);
}

public:

vector<int> a;

fenwickTree(vector<int> & in)
{
int n = in.size();

a = in;
s.assign(n + 1, INT_MAX);
c.assign(n + 1, INT_MAX);

for (int i = 0; i <= n - 1; ++i)
{
Expand All @@ -36,13 +37,13 @@ class fenwickTree
{
++k;

int n = s.size();
int n = a.size();

a[k - 1] = temp;

for (int i = k; i <= n - 1; i += lowbit(i))
for (int i = k; i <= n; i += lowbit(i))
{
s[i] = min(s[i], temp);
c[i] = min(c[i], temp);
}
}

Expand All @@ -54,9 +55,9 @@ class fenwickTree

while (l != r)
{
for (--r; r >= l + lowbit(r); r -= lowbit(r))
for (--r; r > l + lowbit(r); r -= lowbit(r))
{
ans = min(ans, s[r]);
ans = min(ans, c[r]);
}

ans = min(ans, a[r - 1]);
Expand Down Expand Up @@ -104,6 +105,13 @@ int main()
}
}

// for (int i = 0; i <= n - 1; ++i)
// {
// if (i > 0) fout << ' ';
// fout << tree.a[i];
// }
// fout << '\n';

if (in[0] == 'q')
{
fout << tree.query(num[0] - 1, num[1] - 1) << '\n';
Expand All @@ -113,7 +121,7 @@ int main()
int sizeN = num.size();
for (int i = 0; i <= sizeN - 2; ++i)
{
int tempA = a[num[i] - 1], tempB = a[num[i + 1] - 1];
int tempA = tree.a[num[i] - 1], tempB = tree.a[num[i + 1] - 1];
tree.update(num[i] - 1, tempB); tree.update(num[i + 1] - 1, tempA);
}
}
Expand Down
15,012 changes: 15,002 additions & 10 deletions myCpps/RMQWithShifts_UVA12299.in

Large diffs are not rendered by default.

Loading

0 comments on commit 7ec7c57

Please sign in to comment.