답안 #524229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524229 2022-02-08T20:23:11 Z CPSC 돌 무게 재기 (IZhO11_stones) C++14
100 / 100
198 ms 4700 KB
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N = 3e5 + 5;
struct nod {
    int mn;
    int mx;
};
nod tree[4*N],emp;
int lazy[4*N],n,a[N];
nod merge(nod a, nod b) {
    nod x;
    x.mn = min(a.mn,b.mn);
    x.mx = max(a.mx,b.mx);
    return x;
}
void update(int node,int le,int ri,int start,int end,int val) {
	if(lazy[node]) {
		tree[node].mn += lazy[node];
		tree[node].mx += lazy[node];
		if(le != ri) {
			lazy[2*node] += lazy[node];
			lazy[2*node+1] += lazy[node];
		}
		lazy[node]=0;
	}
	if(le > end || ri < start) 
	return ;
	if(start <= le && ri <= end) {
		tree[node].mn += val;
		tree[node].mx += val;
		if(le != ri) {
			lazy[2*node] += val;
			lazy[2*node+1] += val;
		}
		return;
	}
	int mid = (le + ri) / 2;
	update(2*node,le,mid,start,end,val);
	update(2*node+1,mid+1,ri,start,end,val);
	tree[node] = merge(tree[2*node], tree[2*node+1]);
}
nod getans(int node,int le,int ri,int start,int end) {
	if(lazy[node]) {
		tree[node].mn += lazy[node];
		tree[node].mx += lazy[node];
		if(le != ri) {
			lazy[2*node] += lazy[node];
			lazy[2*node+1] += lazy[node];
		}
		lazy[node]=0;
	}
	if(le > end || ri < start) return emp;
	if(start <= le && ri <= end) {
		return tree[node];
	}
	int mid = (le + ri) / 2;
	return merge(getans(2*node,le,mid,start,end), getans(2*node+1,mid+1,ri,start,end));
}
main() {
    emp.mx = -1e9;
    emp.mn = 1e9;
    cin>>n;
    int mx,mxty,ty;
    mx = 0;
    for (int i = 1; i <= n; i++) {
        cin>>a[i]>>ty;
        if (ty == 1)
        update(1,1,n,1,a[i],1); else update(1,1,n,1,a[i],-1);
        if (a[i] > mx) {
            mxty = ty;
            mx = a[i];
        } 
        if (mxty == 1) {
            //if (i == 3) cout<<getans(1,1,n,1,n).mn<<endl;
            if (getans(1,1,n,1,n).mn < 0) cout<<"?"<<endl;
            else cout<<">"<<endl;
            continue;
        } 
        if (mxty == 2) {
            if (getans(1,1,n,1,n).mx > 0) cout<<"?"<<endl;
            else cout<<"<"<<endl;
        }
    }
}

Compilation message

stones.cpp:62:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   62 | main() {
      | ^~~~
stones.cpp: In function 'int main()':
stones.cpp:82:9: warning: 'mxty' may be used uninitialized in this function [-Wmaybe-uninitialized]
   82 |         if (mxty == 2) {
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 16 ms 744 KB Output is correct
11 Correct 105 ms 2544 KB Output is correct
12 Correct 170 ms 4500 KB Output is correct
13 Correct 179 ms 4672 KB Output is correct
14 Correct 178 ms 4608 KB Output is correct
15 Correct 177 ms 4676 KB Output is correct
16 Correct 183 ms 4676 KB Output is correct
17 Correct 179 ms 4676 KB Output is correct
18 Correct 178 ms 4676 KB Output is correct
19 Correct 191 ms 4656 KB Output is correct
20 Correct 184 ms 4632 KB Output is correct
21 Correct 178 ms 4676 KB Output is correct
22 Correct 187 ms 4700 KB Output is correct
23 Correct 178 ms 4676 KB Output is correct
24 Correct 178 ms 4676 KB Output is correct
25 Correct 198 ms 4676 KB Output is correct