Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cctype>
- #include <cstdio>
- #include <cstdlib>
- using namespace std;
- const int imax = 1<<18;
- const int level = 1<<17;
- int tres[imax];
- void updateAll() {
- for (int i = level-1; i > 0; i--) {
- tres[i] = tres[2*i]*tres[2*i+1];
- }
- }
- void mod (int pos, int val) {
- val = (val > 0)?1:(val<0)?-1:0;
- //cout << "modded " << pos<<" "<<val<<endl;
- tres[level+pos] = val;
- int tcal = (level + pos)/2;
- while (tcal > 0) {
- tres[tcal] = tres[tcal*2] * tres[tcal*2+1];
- tcal/=2;
- }
- }
- int get(int beg, int end) {
- if (beg == end)
- return tres[level+beg];
- beg += level;
- end += level;
- int lval = tres[beg];
- int rval = tres[end];
- //cout << "l: " << beg << " " << lval << " r:" << end << " " << rval << endl;
- while (beg/2 != end/2) {
- if (beg%2 == 0) {
- lval *= tres[beg+1];
- }
- if (end%2 == 1) {
- rval *= tres[end-1];
- }
- beg/=2;
- end/=2;
- }
- return lval*rval;
- }
- int main()
- {
- //cout << (1<<17) << " " << (1<<18) << endl;
- while (cin.peek() != EOF) {
- int n, k;
- cin >> n >> k;
- for (int i = 0; i < imax; i++) {
- tres[i] = 0;
- }
- for (int i = 0; i < n; i++) {
- int tmp;
- cin >> tmp;
- tres[level+i] = (tmp<0)?-1:(tmp>0)?1:0;
- }
- updateAll();
- string con;
- for (int i = 0; i < k; i++) {
- char c;
- int a, b;
- cin >> c >> a >> b;
- if (c == 'C') {
- mod(a-1, b);
- }
- else {
- int tst = get(a-1,b-1);
- con += (tst<0)?'-':(tst>0)?'+':'0';
- }
- }
- cout << con << endl;
- cin >> ws; // purge ws
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement