#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vi>;
#define sz(x) int(x.size())
int N;
vll A;
int Q;
struct group
{
int i; //inclusive of the group, not the barrier.
ll Asum;
int winners;
};
struct info
{
int l;
int r;
ll Asum;
int winners;
vector<group> pref;
vector<group> suff;
info()
{
;
}
info(int i)
{
l = r = i;
Asum = A[i];
winners = 1;
}
};
void combine(info& res, const info& A, const info& B) //!
{
res = A;
}
info combine(const info& A, const info& B)
{
info res;
combine(res, A, B);
return res;
}
struct segtree
{
info v;
segtree* left = NULL;
segtree* right = NULL;
segtree()
{
;
}
segtree(int L, int R)
{
if(L == R)
v = info(L);
else
{
left = new segtree(L, (L+R)/2);
right = new segtree((L+R)/2+1, R);
combine(v, left->v, right->v);
}
}
void recompute(int I)
{
if(v.l == v.r)
v = info(v.l);
else
{
if(I <= (v.l+v.r)/2)
left->recompute(I);
else
right->recompute(I);
combine(v, left->v, right->v);
}
}
info range(int L, int R)
{
if(L <= v.l && v.r <= R)
return v;
else if(R <= (v.l+v.r)/2)
return left->range(L, R);
else if(L >= (v.l+v.r)/2+1)
return right->range(L, R);
else
return combine(left->range(L, R), right->range(L, R));
}
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
A = vll(1+N);
for(int i = 1; i <= N; i++)
cin >> A[i];
// cerr << "done\n";
segtree S(1, N);
// cerr << "done2\n";
cin >> Q;
for(int j = 1; j <= Q; j++)
{
int T;
cin >> T;
if(T == 1)
{
int X, Y;
cin >> X >> Y;
A[X] = Y;
S.recompute(X);
// cerr << "hello\n";
}
else
{
int L, R;
cin >> L >> R;
cout << S.range(L, R).winners << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |