Submission #48428

# Submission time Handle Problem Language Result Execution time Memory
48428 2018-05-13T09:57:12 Z ernestvw Weighting stones (IZhO11_stones) C++11
100 / 100
206 ms 13996 KB
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
const int maxn = 1<<17;

class SegmentTree {
public:
    int n;
    vi sum,minsuffix,maxsuffix;
    SegmentTree(int _n) : n(_n), sum(2*_n,0),
        minsuffix(2*_n,0), maxsuffix(2*_n,0) {}
    void update(int i,int v) {
        i+=n;
        maxsuffix[i]=minsuffix[i]=sum[i]=v;
        while((i/=2)>0) {
            sum[i]=sum[2*i]+sum[2*i+1];
            minsuffix[i]=min(minsuffix[2*i]+sum[2*i+1],minsuffix[2*i+1]);
            maxsuffix[i]=max(maxsuffix[2*i]+sum[2*i+1],maxsuffix[2*i+1]);
        }
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N;
    cin>>N;
    SegmentTree segTree(maxn);
    for(int i=1;i<=N;i++) {
        int w;
        int s;
        cin>>w>>s;
        segTree.update(w-1, s==1 ? 1 : -1);
        bool rHeavier = segTree.minsuffix[1]<0;
        bool lHeavier = segTree.maxsuffix[1]>0;
        if(rHeavier && lHeavier) cout<<'?'<<endl;
        else if(rHeavier) cout<<'<'<<endl;
        else if(lHeavier) cout<<'>'<<endl;
    }
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 5 ms 3448 KB Output is correct
3 Correct 5 ms 3612 KB Output is correct
4 Correct 4 ms 3612 KB Output is correct
5 Correct 5 ms 3612 KB Output is correct
6 Correct 5 ms 3612 KB Output is correct
7 Correct 6 ms 3648 KB Output is correct
8 Correct 6 ms 3668 KB Output is correct
9 Correct 6 ms 3684 KB Output is correct
10 Correct 20 ms 3812 KB Output is correct
11 Correct 125 ms 3948 KB Output is correct
12 Correct 173 ms 3964 KB Output is correct
13 Correct 176 ms 4860 KB Output is correct
14 Correct 181 ms 5552 KB Output is correct
15 Correct 192 ms 6244 KB Output is correct
16 Correct 185 ms 7024 KB Output is correct
17 Correct 184 ms 7892 KB Output is correct
18 Correct 177 ms 8776 KB Output is correct
19 Correct 178 ms 9348 KB Output is correct
20 Correct 177 ms 10120 KB Output is correct
21 Correct 183 ms 10996 KB Output is correct
22 Correct 206 ms 11824 KB Output is correct
23 Correct 178 ms 12564 KB Output is correct
24 Correct 177 ms 13336 KB Output is correct
25 Correct 172 ms 13996 KB Output is correct