Submission #202636

# Submission time Handle Problem Language Result Execution time Memory
202636 2020-02-17T12:01:33 Z dndhk Fire (JOI20_ho_t5) C++14
100 / 100
279 ms 18668 KB
#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

const int MAX_N = 200000;

int N, Q;
int S[MAX_N+1];

struct ST{
	int t, l, r, idx;
	bool operator <(const ST &a)const{
		return t<a.t;
	}
};

vector<ST> vt;


struct SEG{
	struct NODE{
		int l, r;
		int mx;
	};
	vector<NODE> seg;
	int SZ;
	void add(){
		seg.pb({-1, -1, 0});
	}
	void Init(int x){
		SZ = x;
		add(); init(0, 1, SZ);
	}
	void init(int idx, int s, int e){
		if(s==e)	{
			seg[idx].mx = S[s];
			return;
		}
		seg[idx].l = seg.size(); add();
		seg[idx].r = seg.size(); add();
		init(seg[idx].l, s, (s+e)/2);
		init(seg[idx].r, (s+e)/2+1, e);
		seg[idx].mx = max(seg[seg[idx].l].mx, seg[seg[idx].r].mx);
	}
	int  Mx(int x, int y){
		return mx(0, 1, SZ, x, y);
	}
	int mx(int idx, int s, int e, int x, int y){
		if(x>e || y<s)	return 0;
		if(x<=s && e<=y)	return seg[idx].mx;
		return max(mx(seg[idx].l, s, (s+e)/2, x, y), mx(seg[idx].r, (s+e)/2+1, e, x, y));
	}
}Seg;

void solve1(){
	Seg.Init(N);
	for(int i=0; i<vt.size(); i++){
		ST now = vt[i];
		ll answer = 0;
		for(int j=now.l; j<=now.r; j++){
			answer += (ll)Seg.Mx(j-now.t, j);
		}
		printf("%lld\n", answer);
	}
}

ll tree[MAX_N+1];

void upd(int x, ll y){
	while(x<=N){
		tree[x]+=y;
		x+=(x&-x);
	}
}

ll Sum(int x){
	ll ret = 0;
	while(x>0){
		ret+=tree[x];
		x-=(x&-x);
	}
	return ret;
}

void solve2(){
	Seg.Init(N);
	int T = vt[0].t;
	for(int i=1; i<=N; i++){
		upd(i, (ll)Seg.Mx(i-T, i));
	}
	for(int i=0; i<vt.size(); i++){
		ST now = vt[i];
		printf("%lld\n", Sum(now.r) - Sum(now.l-1));
	}
}

void solve3(){
	Seg.Init(N);
	for(int i=0; i<vt.size(); i++){
		ST now = vt[i];
		printf("%lld\n", (ll)Seg.Mx(now.l-now.t, now.l));
	}
}

ll ans[MAX_N+1];

vector<pii> v, v2;

void solve4(){
	Seg.Init(N);
	sort(vt.begin(), vt.end());
	int T = 0;
	for(int i=1; i<=N; i++){
		upd(i, S[i]);
		if(S[i]!=0){
			v.pb({i, S[i]});
		}
	}
	for(int i=0; i<vt.size(); i++){
		ST now = vt[i];
		while(T<now.t){
			T++;
			while(!v.empty()){
				pii n = v.back(); v.pop_back();
				if(n.first==N)	continue;
				if(S[n.first+1]<n.second){
					upd(n.first+1, (ll)(n.second-S[n.first+1]));
					S[n.first+1] = n.second;
					v2.pb({n.first+1, n.second});
				}
			}
			while(!v2.empty()){
				v.pb(v2.back()); v2.pop_back();
			}
		}
		ans[now.idx] = Sum(now.r) - Sum(now.l-1);
	}
	for(int i=1; i<=Q; i++){
		printf("%lld\n", ans[i]);
	}
}
int main(){
	scanf("%d%d", &N, &Q);
	for(int i=1; i<=N; i++){
		scanf("%d", &S[i]);
	}
	bool tf2 = true, tf3 = true;
	for(int i=1; i<=Q; i++){
		int t, l, r; scanf("%d%d%d", &t, &l, &r);
		vt.pb({t, l, r, i});
		if(t!=vt[0].t)	tf2 = false;
		if(l!=r)	tf3 = false;
	}
	if(N<=200 && Q<=200){
		solve1();
	}else if(tf2){
		solve2();
	}else if(tf3){
		solve3();
	}else{
		solve4();
	}
	return 0;
}

Compilation message

ho_t5.cpp: In function 'void solve1()':
ho_t5.cpp:63:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<vt.size(); i++){
               ~^~~~~~~~~~
ho_t5.cpp: In function 'void solve2()':
ho_t5.cpp:97:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<vt.size(); i++){
               ~^~~~~~~~~~
ho_t5.cpp: In function 'void solve3()':
ho_t5.cpp:105:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<vt.size(); i++){
               ~^~~~~~~~~~
ho_t5.cpp: In function 'void solve4()':
ho_t5.cpp:125:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<vt.size(); i++){
               ~^~~~~~~~~~
ho_t5.cpp: In function 'int main()':
ho_t5.cpp:149:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &Q);
  ~~~~~^~~~~~~~~~~~~~~~
ho_t5.cpp:151:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &S[i]);
   ~~~~~^~~~~~~~~~~~~
ho_t5.cpp:155:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int t, l, r; scanf("%d%d%d", &t, &l, &r);
                ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 7 ms 380 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 7 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 7 ms 376 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 6 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 7 ms 376 KB Output is correct
32 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 212 ms 16208 KB Output is correct
3 Correct 219 ms 16080 KB Output is correct
4 Correct 242 ms 16336 KB Output is correct
5 Correct 211 ms 16212 KB Output is correct
6 Correct 227 ms 16208 KB Output is correct
7 Correct 219 ms 16464 KB Output is correct
8 Correct 234 ms 16464 KB Output is correct
9 Correct 232 ms 16508 KB Output is correct
10 Correct 217 ms 16080 KB Output is correct
11 Correct 233 ms 16592 KB Output is correct
12 Correct 211 ms 16208 KB Output is correct
13 Correct 245 ms 16336 KB Output is correct
14 Correct 229 ms 16208 KB Output is correct
15 Correct 228 ms 16328 KB Output is correct
16 Correct 242 ms 16208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 277 ms 13932 KB Output is correct
3 Correct 245 ms 13648 KB Output is correct
4 Correct 245 ms 14024 KB Output is correct
5 Correct 234 ms 13648 KB Output is correct
6 Correct 248 ms 13776 KB Output is correct
7 Correct 250 ms 13964 KB Output is correct
8 Correct 249 ms 13776 KB Output is correct
9 Correct 239 ms 13676 KB Output is correct
10 Correct 235 ms 13520 KB Output is correct
11 Correct 257 ms 13976 KB Output is correct
12 Correct 231 ms 13776 KB Output is correct
13 Correct 251 ms 13904 KB Output is correct
14 Correct 249 ms 13780 KB Output is correct
15 Correct 256 ms 13904 KB Output is correct
16 Correct 243 ms 13780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 16464 KB Output is correct
2 Correct 178 ms 16592 KB Output is correct
3 Correct 183 ms 16856 KB Output is correct
4 Correct 189 ms 16460 KB Output is correct
5 Correct 181 ms 16592 KB Output is correct
6 Correct 177 ms 16464 KB Output is correct
7 Correct 173 ms 16720 KB Output is correct
8 Correct 185 ms 16720 KB Output is correct
9 Correct 176 ms 16464 KB Output is correct
10 Correct 186 ms 16772 KB Output is correct
11 Correct 180 ms 16612 KB Output is correct
12 Correct 179 ms 16592 KB Output is correct
13 Correct 179 ms 16592 KB Output is correct
14 Correct 179 ms 16720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 7 ms 376 KB Output is correct
4 Correct 7 ms 380 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 7 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 6 ms 376 KB Output is correct
12 Correct 6 ms 376 KB Output is correct
13 Correct 6 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 6 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 7 ms 376 KB Output is correct
25 Correct 6 ms 376 KB Output is correct
26 Correct 6 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 6 ms 376 KB Output is correct
29 Correct 6 ms 376 KB Output is correct
30 Correct 6 ms 376 KB Output is correct
31 Correct 7 ms 376 KB Output is correct
32 Correct 6 ms 376 KB Output is correct
33 Correct 267 ms 18256 KB Output is correct
34 Correct 279 ms 18668 KB Output is correct
35 Correct 267 ms 18384 KB Output is correct
36 Correct 270 ms 18256 KB Output is correct
37 Correct 278 ms 18128 KB Output is correct
38 Correct 276 ms 18384 KB Output is correct
39 Correct 269 ms 18256 KB Output is correct
40 Correct 268 ms 18396 KB Output is correct
41 Correct 272 ms 18512 KB Output is correct
42 Correct 272 ms 18256 KB Output is correct
43 Correct 262 ms 18512 KB Output is correct
44 Correct 263 ms 18512 KB Output is correct
45 Correct 251 ms 18128 KB Output is correct
46 Correct 267 ms 18256 KB Output is correct
47 Correct 278 ms 18128 KB Output is correct
48 Correct 266 ms 18004 KB Output is correct
49 Correct 257 ms 18128 KB Output is correct
50 Correct 275 ms 18512 KB Output is correct
51 Correct 263 ms 18512 KB Output is correct
52 Correct 270 ms 18256 KB Output is correct
53 Correct 265 ms 18384 KB Output is correct
54 Correct 253 ms 18136 KB Output is correct
55 Correct 250 ms 18128 KB Output is correct
56 Correct 258 ms 18256 KB Output is correct
57 Correct 254 ms 18128 KB Output is correct
58 Correct 267 ms 18512 KB Output is correct
59 Correct 212 ms 16208 KB Output is correct
60 Correct 219 ms 16080 KB Output is correct
61 Correct 242 ms 16336 KB Output is correct
62 Correct 211 ms 16212 KB Output is correct
63 Correct 227 ms 16208 KB Output is correct
64 Correct 219 ms 16464 KB Output is correct
65 Correct 234 ms 16464 KB Output is correct
66 Correct 232 ms 16508 KB Output is correct
67 Correct 217 ms 16080 KB Output is correct
68 Correct 233 ms 16592 KB Output is correct
69 Correct 211 ms 16208 KB Output is correct
70 Correct 245 ms 16336 KB Output is correct
71 Correct 229 ms 16208 KB Output is correct
72 Correct 228 ms 16328 KB Output is correct
73 Correct 242 ms 16208 KB Output is correct
74 Correct 277 ms 13932 KB Output is correct
75 Correct 245 ms 13648 KB Output is correct
76 Correct 245 ms 14024 KB Output is correct
77 Correct 234 ms 13648 KB Output is correct
78 Correct 248 ms 13776 KB Output is correct
79 Correct 250 ms 13964 KB Output is correct
80 Correct 249 ms 13776 KB Output is correct
81 Correct 239 ms 13676 KB Output is correct
82 Correct 235 ms 13520 KB Output is correct
83 Correct 257 ms 13976 KB Output is correct
84 Correct 231 ms 13776 KB Output is correct
85 Correct 251 ms 13904 KB Output is correct
86 Correct 249 ms 13780 KB Output is correct
87 Correct 256 ms 13904 KB Output is correct
88 Correct 243 ms 13780 KB Output is correct
89 Correct 174 ms 16464 KB Output is correct
90 Correct 178 ms 16592 KB Output is correct
91 Correct 183 ms 16856 KB Output is correct
92 Correct 189 ms 16460 KB Output is correct
93 Correct 181 ms 16592 KB Output is correct
94 Correct 177 ms 16464 KB Output is correct
95 Correct 173 ms 16720 KB Output is correct
96 Correct 185 ms 16720 KB Output is correct
97 Correct 176 ms 16464 KB Output is correct
98 Correct 186 ms 16772 KB Output is correct
99 Correct 180 ms 16612 KB Output is correct
100 Correct 179 ms 16592 KB Output is correct
101 Correct 179 ms 16592 KB Output is correct
102 Correct 179 ms 16720 KB Output is correct