Submission #286777

# Submission time Handle Problem Language Result Execution time Memory
286777 2020-08-30T22:09:16 Z errorgorn Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2272 ms 185788 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,q;
int arr[1000005];

const int INF=2e9;

struct node{
	int s,e,m;
	int val,lazy=0;
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
			
			val=max(l->val,r->val);
		}
		else{
			val=arr[s]-INF;
		}
	}
	
	void propo(){
		if (lazy){
			val+=lazy;
			if (s!=e){
				l->lazy+=lazy;
				r->lazy+=lazy;
			}
			lazy=0;
		}
	}
	
	void update(int i,int j,int k){
		if (s==i && e==j) lazy+=k;
		else{
			if (j<=m) l->update(i,j,k);
			else if (m<i) r->update(i,j,k);
			else l->update(i,m,k),r->update(m+1,j,k);
			
			l->propo(),r->propo();
			
			val=max(l->val,r->val);
		}
	}
	
	int query(int i,int j){
		propo();
		if (s==i && e==j) return val;
		else if (j<=m) return l->query(i,j);
		else if (m<i) return r->query(i,j);
		else return max(l->query(i,m),r->query(m+1,j));
	}
} *root;

priority_queue<ii,vector<ii>,greater<ii> > pq; //check which nodes can remove INF

struct Q{
	int l,r;
	int lim;
	int idx;
	
	Q(int a,int b,int c,int d){
		l=a,r=b,lim=c,idx=d;
	}
};
vector<Q> queries;
int ans[1000005];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);
	
	cin>>n>>q;
	rep(x,0,n) cin>>arr[x];
	
	root=new node(0,n+5); //hm
	
	int a,b,c;
	rep(x,0,q){
		cin>>a>>b>>c;
		queries.push_back(Q(a-1,b-1,c,x));
	}
	
	sort(all(queries),[](Q &i,Q &j){
		return i.l>j.l;
	});
	
	int curr=n;
	vector<int> stk={n};
	for (auto &it:queries){
		while (curr!=it.l){
			curr--;
			
			while (stk.back()!=n && arr[stk.back()]<=arr[curr]){
				int temp=stk.back();
				stk.pop_back();
				root->update(temp,stk.back()-1,arr[curr]-arr[temp]);
			}
			stk.push_back(curr);
			root->update(curr,curr,arr[curr]);
			
			while (!pq.empty() && pq.top().fi<arr[curr]){
				root->update(pq.top().se,pq.top().se,INF);
				pq.pop();
			}
			
			pq.push(ii(arr[curr],curr));
		}
		
		//cout<<root->query(it.l,it.r)<<endl;
		ans[it.idx]=root->query(it.l,it.r)<=it.lim;
	}
	
	rep(x,0,q) cout<<ans[x]<<endl;
}

Compilation message

sortbooks.cpp: In constructor 'node::node(int, int)':
sortbooks.cpp:39:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 5 ms 1024 KB Output is correct
13 Correct 6 ms 1024 KB Output is correct
14 Correct 7 ms 1280 KB Output is correct
15 Correct 7 ms 1280 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 6 ms 1152 KB Output is correct
18 Correct 9 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2256 ms 120168 KB Output is correct
2 Correct 2272 ms 120000 KB Output is correct
3 Correct 2260 ms 120248 KB Output is correct
4 Correct 2237 ms 120108 KB Output is correct
5 Correct 1843 ms 152164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 12392 KB Output is correct
2 Correct 146 ms 14440 KB Output is correct
3 Correct 142 ms 17128 KB Output is correct
4 Correct 148 ms 17132 KB Output is correct
5 Correct 147 ms 17132 KB Output is correct
6 Correct 129 ms 16620 KB Output is correct
7 Correct 128 ms 16616 KB Output is correct
8 Correct 158 ms 15724 KB Output is correct
9 Correct 47 ms 4072 KB Output is correct
10 Correct 178 ms 15844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 5 ms 1024 KB Output is correct
13 Correct 6 ms 1024 KB Output is correct
14 Correct 7 ms 1280 KB Output is correct
15 Correct 7 ms 1280 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 6 ms 1152 KB Output is correct
18 Correct 9 ms 1152 KB Output is correct
19 Correct 375 ms 28256 KB Output is correct
20 Correct 369 ms 30924 KB Output is correct
21 Correct 320 ms 30820 KB Output is correct
22 Correct 321 ms 30816 KB Output is correct
23 Correct 316 ms 30816 KB Output is correct
24 Correct 247 ms 37856 KB Output is correct
25 Correct 247 ms 37856 KB Output is correct
26 Correct 264 ms 37984 KB Output is correct
27 Correct 269 ms 38112 KB Output is correct
28 Correct 276 ms 37984 KB Output is correct
29 Correct 296 ms 38188 KB Output is correct
30 Correct 295 ms 38112 KB Output is correct
31 Correct 298 ms 38120 KB Output is correct
32 Correct 292 ms 38112 KB Output is correct
33 Correct 293 ms 38116 KB Output is correct
34 Correct 243 ms 37856 KB Output is correct
35 Correct 248 ms 37728 KB Output is correct
36 Correct 236 ms 37472 KB Output is correct
37 Correct 239 ms 37476 KB Output is correct
38 Correct 242 ms 37856 KB Output is correct
39 Correct 295 ms 35788 KB Output is correct
40 Correct 220 ms 25568 KB Output is correct
41 Correct 351 ms 32484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 3 ms 640 KB Output is correct
12 Correct 5 ms 1024 KB Output is correct
13 Correct 6 ms 1024 KB Output is correct
14 Correct 7 ms 1280 KB Output is correct
15 Correct 7 ms 1280 KB Output is correct
16 Correct 6 ms 1152 KB Output is correct
17 Correct 6 ms 1152 KB Output is correct
18 Correct 9 ms 1152 KB Output is correct
19 Correct 2256 ms 120168 KB Output is correct
20 Correct 2272 ms 120000 KB Output is correct
21 Correct 2260 ms 120248 KB Output is correct
22 Correct 2237 ms 120108 KB Output is correct
23 Correct 1843 ms 152164 KB Output is correct
24 Correct 157 ms 12392 KB Output is correct
25 Correct 146 ms 14440 KB Output is correct
26 Correct 142 ms 17128 KB Output is correct
27 Correct 148 ms 17132 KB Output is correct
28 Correct 147 ms 17132 KB Output is correct
29 Correct 129 ms 16620 KB Output is correct
30 Correct 128 ms 16616 KB Output is correct
31 Correct 158 ms 15724 KB Output is correct
32 Correct 47 ms 4072 KB Output is correct
33 Correct 178 ms 15844 KB Output is correct
34 Correct 375 ms 28256 KB Output is correct
35 Correct 369 ms 30924 KB Output is correct
36 Correct 320 ms 30820 KB Output is correct
37 Correct 321 ms 30816 KB Output is correct
38 Correct 316 ms 30816 KB Output is correct
39 Correct 247 ms 37856 KB Output is correct
40 Correct 247 ms 37856 KB Output is correct
41 Correct 264 ms 37984 KB Output is correct
42 Correct 269 ms 38112 KB Output is correct
43 Correct 276 ms 37984 KB Output is correct
44 Correct 296 ms 38188 KB Output is correct
45 Correct 295 ms 38112 KB Output is correct
46 Correct 298 ms 38120 KB Output is correct
47 Correct 292 ms 38112 KB Output is correct
48 Correct 293 ms 38116 KB Output is correct
49 Correct 243 ms 37856 KB Output is correct
50 Correct 248 ms 37728 KB Output is correct
51 Correct 236 ms 37472 KB Output is correct
52 Correct 239 ms 37476 KB Output is correct
53 Correct 242 ms 37856 KB Output is correct
54 Correct 295 ms 35788 KB Output is correct
55 Correct 220 ms 25568 KB Output is correct
56 Correct 351 ms 32484 KB Output is correct
57 Correct 2202 ms 153564 KB Output is correct
58 Correct 2220 ms 153656 KB Output is correct
59 Correct 2051 ms 153564 KB Output is correct
60 Correct 2086 ms 153544 KB Output is correct
61 Correct 2065 ms 153536 KB Output is correct
62 Correct 2051 ms 153456 KB Output is correct
63 Correct 1336 ms 183480 KB Output is correct
64 Correct 1352 ms 183724 KB Output is correct
65 Correct 1665 ms 185516 KB Output is correct
66 Correct 1674 ms 185360 KB Output is correct
67 Correct 1687 ms 185544 KB Output is correct
68 Correct 1798 ms 185576 KB Output is correct
69 Correct 1795 ms 185204 KB Output is correct
70 Correct 1801 ms 185440 KB Output is correct
71 Correct 1794 ms 185788 KB Output is correct
72 Correct 1763 ms 185392 KB Output is correct
73 Correct 1283 ms 181936 KB Output is correct
74 Correct 1332 ms 183124 KB Output is correct
75 Correct 1280 ms 181956 KB Output is correct
76 Correct 1270 ms 182004 KB Output is correct
77 Correct 1267 ms 181960 KB Output is correct
78 Correct 1731 ms 174064 KB Output is correct
79 Correct 1227 ms 110356 KB Output is correct
80 Correct 2155 ms 160444 KB Output is correct