답안 #377846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377846 2021-03-15T10:37:30 Z astoria 역사적 조사 (JOI14_historical) C++14
40 / 100
4000 ms 130028 KB
#include "bits/stdc++.h"
using namespace std;

const int N=1e5+5,Q=1e5+5;
const int S = 600;
struct Query{
	int l,r,p,bk;
};
Query qr[Q];
int n,q,x[N];

struct node{
	int s,e,m; long long val;
	node *l, *r;
	node(int _s, int _e){
		s=_s; e=_e;
		m=(s+e)>>1;
		val = 0;
	}
	
	void create(){
		if(s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	
	void upd(int p, int v){
		if(s==e) val += (long long) v;
		else{
			if(l==NULL) create();
			if(p<=m) l->upd(p,v);
			else r->upd(p,v);
			
			val = max(l->val,r->val);
		}
	}
	
	long long qry(){
		return val;
	}
	
} *root;

bool comp(Query A, Query B){
	if(A.bk != B.bk) return A.bk < B.bk;
	return A.bk % 2 ? A.r > B.r : A.r < B.r;
}

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>n>>q;
	for(int i=1; i<=n; i++) cin>>x[i];
	for(int i=0; i<q; i++){
		cin>>qr[i].l>>qr[i].r;
		qr[i].p = i;
		qr[i].bk = qr[i].l / S;
	}
	sort(qr,qr+q,comp);
	
	root = new node(0,(int) 1e9+5);
	
	int mo_left = 1, mo_right = 0;
	
	long long ans[q];
	
	for(int i=0; i<q; i++){
		int left = qr[i].l, right = qr[i].r;
		while(mo_right < right){
			++mo_right;
			int t = x[mo_right];
			root->upd(t,t);
		}
		while(mo_left > left){
			--mo_left;
			int t = x[mo_left];
			root->upd(t,t);
		}
		while(mo_right > right){
			int t = x[mo_right];
			root->upd(t,-t);
			--mo_right;
		}
		while(mo_left < left){
			int t = x[mo_left];
			root->upd(t,-t);
			++mo_left;
		}
		ans[qr[i].p] = root->qry();
		//cout<<"HI"<<endl;
		//cout<<qr[i].l<<' '<<qr[i].r<<' '<<ans[qr[i].p]<<endl;
	}
	
	for(int i=0; i<q; i++) cout<<ans[i]<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 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 364 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 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 364 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 9 ms 492 KB Output is correct
18 Correct 33 ms 620 KB Output is correct
19 Correct 79 ms 784 KB Output is correct
20 Correct 154 ms 748 KB Output is correct
21 Correct 226 ms 748 KB Output is correct
22 Correct 228 ms 768 KB Output is correct
23 Correct 199 ms 620 KB Output is correct
24 Correct 197 ms 748 KB Output is correct
25 Correct 246 ms 1132 KB Output is correct
26 Correct 286 ms 2124 KB Output is correct
27 Correct 317 ms 2688 KB Output is correct
28 Correct 330 ms 2924 KB Output is correct
29 Correct 331 ms 2156 KB Output is correct
30 Correct 326 ms 2540 KB Output is correct
31 Correct 238 ms 748 KB Output is correct
32 Correct 182 ms 876 KB Output is correct
33 Correct 316 ms 2412 KB Output is correct
34 Correct 339 ms 3948 KB Output is correct
35 Correct 352 ms 4588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 4 ms 1132 KB Output is correct
6 Correct 5 ms 492 KB Output is correct
7 Correct 13 ms 2156 KB Output is correct
8 Correct 21 ms 5888 KB Output is correct
9 Correct 54 ms 11756 KB Output is correct
10 Correct 33 ms 1004 KB Output is correct
11 Correct 126 ms 4844 KB Output is correct
12 Correct 70 ms 2028 KB Output is correct
13 Correct 203 ms 11112 KB Output is correct
14 Correct 367 ms 59372 KB Output is correct
15 Correct 354 ms 82500 KB Output is correct
16 Correct 347 ms 130028 KB Output is correct
17 Correct 57 ms 2284 KB Output is correct
18 Correct 123 ms 5100 KB Output is correct
19 Correct 123 ms 14828 KB Output is correct
20 Correct 152 ms 88428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 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 364 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 9 ms 492 KB Output is correct
18 Correct 33 ms 620 KB Output is correct
19 Correct 79 ms 784 KB Output is correct
20 Correct 154 ms 748 KB Output is correct
21 Correct 226 ms 748 KB Output is correct
22 Correct 228 ms 768 KB Output is correct
23 Correct 199 ms 620 KB Output is correct
24 Correct 197 ms 748 KB Output is correct
25 Correct 246 ms 1132 KB Output is correct
26 Correct 286 ms 2124 KB Output is correct
27 Correct 317 ms 2688 KB Output is correct
28 Correct 330 ms 2924 KB Output is correct
29 Correct 331 ms 2156 KB Output is correct
30 Correct 326 ms 2540 KB Output is correct
31 Correct 238 ms 748 KB Output is correct
32 Correct 182 ms 876 KB Output is correct
33 Correct 316 ms 2412 KB Output is correct
34 Correct 339 ms 3948 KB Output is correct
35 Correct 352 ms 4588 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 4 ms 1132 KB Output is correct
41 Correct 5 ms 492 KB Output is correct
42 Correct 13 ms 2156 KB Output is correct
43 Correct 21 ms 5888 KB Output is correct
44 Correct 54 ms 11756 KB Output is correct
45 Correct 33 ms 1004 KB Output is correct
46 Correct 126 ms 4844 KB Output is correct
47 Correct 70 ms 2028 KB Output is correct
48 Correct 203 ms 11112 KB Output is correct
49 Correct 367 ms 59372 KB Output is correct
50 Correct 354 ms 82500 KB Output is correct
51 Correct 347 ms 130028 KB Output is correct
52 Correct 57 ms 2284 KB Output is correct
53 Correct 123 ms 5100 KB Output is correct
54 Correct 123 ms 14828 KB Output is correct
55 Correct 152 ms 88428 KB Output is correct
56 Correct 481 ms 1004 KB Output is correct
57 Correct 1222 ms 2188 KB Output is correct
58 Correct 2170 ms 5612 KB Output is correct
59 Correct 3560 ms 13808 KB Output is correct
60 Execution timed out 4026 ms 16620 KB Time limit exceeded
61 Halted 0 ms 0 KB -