답안 #480108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480108 2021-10-14T16:16:25 Z HynDuf Fire (JOI20_ho_t5) C++11
100 / 100
241 ms 21532 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;
 
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;
}

 
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]);
	}
	for(int i=1; i<=Q; i++){
		int t, l, r; scanf("%d%d%d", &t, &l, &r);
		vt.pb({t, l, r, i});
	}
	solve4();
	return 0;
}

Compilation message

ho_t5.cpp: In function 'void solve4()':
ho_t5.cpp:94:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<ST>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |  for(int i=0; i<vt.size(); i++){
      |               ~^~~~~~~~~~
ho_t5.cpp: In function 'int main()':
ho_t5.cpp:118:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |  scanf("%d%d", &N, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~
ho_t5.cpp:120:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |   scanf("%d", &S[i]);
      |   ~~~~~^~~~~~~~~~~~~
ho_t5.cpp:123:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  123 |   int t, l, r; scanf("%d%d%d", &t, &l, &r);
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 304 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 212 ms 21124 KB Output is correct
3 Correct 192 ms 21072 KB Output is correct
4 Correct 201 ms 21264 KB Output is correct
5 Correct 204 ms 21244 KB Output is correct
6 Correct 195 ms 21112 KB Output is correct
7 Correct 203 ms 21380 KB Output is correct
8 Correct 189 ms 21412 KB Output is correct
9 Correct 221 ms 21380 KB Output is correct
10 Correct 189 ms 21020 KB Output is correct
11 Correct 198 ms 21404 KB Output is correct
12 Correct 205 ms 21032 KB Output is correct
13 Correct 190 ms 21208 KB Output is correct
14 Correct 224 ms 21196 KB Output is correct
15 Correct 196 ms 21244 KB Output is correct
16 Correct 204 ms 21108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 227 ms 20360 KB Output is correct
3 Correct 212 ms 20020 KB Output is correct
4 Correct 233 ms 20744 KB Output is correct
5 Correct 204 ms 19992 KB Output is correct
6 Correct 221 ms 20252 KB Output is correct
7 Correct 227 ms 20252 KB Output is correct
8 Correct 214 ms 20308 KB Output is correct
9 Correct 217 ms 20076 KB Output is correct
10 Correct 199 ms 19868 KB Output is correct
11 Correct 216 ms 20588 KB Output is correct
12 Correct 217 ms 20264 KB Output is correct
13 Correct 227 ms 20380 KB Output is correct
14 Correct 213 ms 20132 KB Output is correct
15 Correct 219 ms 20376 KB Output is correct
16 Correct 224 ms 20240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 19356 KB Output is correct
2 Correct 151 ms 19284 KB Output is correct
3 Correct 151 ms 19632 KB Output is correct
4 Correct 143 ms 19424 KB Output is correct
5 Correct 149 ms 19352 KB Output is correct
6 Correct 143 ms 19368 KB Output is correct
7 Correct 146 ms 19612 KB Output is correct
8 Correct 144 ms 19612 KB Output is correct
9 Correct 149 ms 19356 KB Output is correct
10 Correct 154 ms 19456 KB Output is correct
11 Correct 145 ms 19548 KB Output is correct
12 Correct 149 ms 19544 KB Output is correct
13 Correct 155 ms 19484 KB Output is correct
14 Correct 146 ms 19664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 304 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 304 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 308 KB Output is correct
33 Correct 212 ms 21124 KB Output is correct
34 Correct 192 ms 21072 KB Output is correct
35 Correct 201 ms 21264 KB Output is correct
36 Correct 204 ms 21244 KB Output is correct
37 Correct 195 ms 21112 KB Output is correct
38 Correct 203 ms 21380 KB Output is correct
39 Correct 189 ms 21412 KB Output is correct
40 Correct 221 ms 21380 KB Output is correct
41 Correct 189 ms 21020 KB Output is correct
42 Correct 198 ms 21404 KB Output is correct
43 Correct 205 ms 21032 KB Output is correct
44 Correct 190 ms 21208 KB Output is correct
45 Correct 224 ms 21196 KB Output is correct
46 Correct 196 ms 21244 KB Output is correct
47 Correct 204 ms 21108 KB Output is correct
48 Correct 227 ms 20360 KB Output is correct
49 Correct 212 ms 20020 KB Output is correct
50 Correct 233 ms 20744 KB Output is correct
51 Correct 204 ms 19992 KB Output is correct
52 Correct 221 ms 20252 KB Output is correct
53 Correct 227 ms 20252 KB Output is correct
54 Correct 214 ms 20308 KB Output is correct
55 Correct 217 ms 20076 KB Output is correct
56 Correct 199 ms 19868 KB Output is correct
57 Correct 216 ms 20588 KB Output is correct
58 Correct 217 ms 20264 KB Output is correct
59 Correct 227 ms 20380 KB Output is correct
60 Correct 213 ms 20132 KB Output is correct
61 Correct 219 ms 20376 KB Output is correct
62 Correct 224 ms 20240 KB Output is correct
63 Correct 155 ms 19356 KB Output is correct
64 Correct 151 ms 19284 KB Output is correct
65 Correct 151 ms 19632 KB Output is correct
66 Correct 143 ms 19424 KB Output is correct
67 Correct 149 ms 19352 KB Output is correct
68 Correct 143 ms 19368 KB Output is correct
69 Correct 146 ms 19612 KB Output is correct
70 Correct 144 ms 19612 KB Output is correct
71 Correct 149 ms 19356 KB Output is correct
72 Correct 154 ms 19456 KB Output is correct
73 Correct 145 ms 19548 KB Output is correct
74 Correct 149 ms 19544 KB Output is correct
75 Correct 155 ms 19484 KB Output is correct
76 Correct 146 ms 19664 KB Output is correct
77 Correct 222 ms 21376 KB Output is correct
78 Correct 216 ms 21532 KB Output is correct
79 Correct 233 ms 21504 KB Output is correct
80 Correct 212 ms 21368 KB Output is correct
81 Correct 218 ms 21192 KB Output is correct
82 Correct 221 ms 21248 KB Output is correct
83 Correct 218 ms 21148 KB Output is correct
84 Correct 219 ms 21028 KB Output is correct
85 Correct 224 ms 21056 KB Output is correct
86 Correct 221 ms 21020 KB Output is correct
87 Correct 218 ms 21264 KB Output is correct
88 Correct 223 ms 21116 KB Output is correct
89 Correct 208 ms 20756 KB Output is correct
90 Correct 211 ms 20908 KB Output is correct
91 Correct 241 ms 20520 KB Output is correct
92 Correct 209 ms 20472 KB Output is correct
93 Correct 215 ms 20524 KB Output is correct
94 Correct 214 ms 20916 KB Output is correct
95 Correct 217 ms 20636 KB Output is correct
96 Correct 216 ms 20624 KB Output is correct
97 Correct 229 ms 20420 KB Output is correct
98 Correct 213 ms 20188 KB Output is correct
99 Correct 196 ms 19988 KB Output is correct
100 Correct 224 ms 20252 KB Output is correct
101 Correct 212 ms 19904 KB Output is correct
102 Correct 226 ms 20148 KB Output is correct