Submission #151010

# Submission time Handle Problem Language Result Execution time Memory
151010 2019-09-01T14:47:20 Z username Triple Jump (JOI19_jumps) C++14
100 / 100
1669 ms 122268 KB
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define REP(i,j,k) for(int i=(j);i<(k);++i)
#define RREP(i,j,k) for(int i=int(j)-1;i>=(k);--i)
#define pb push_back
#define f first
#define s second
#define MAX(x,y) (x=max(x,(y)))
#define mid (l+r>>1)
#define lch (idx*2+1)
#define rch (idx*2+2)
#define endl '\n'
#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)

const int lg=19,maxn=1<<lg;
int n,q,a[maxn],res[maxn],dat[2*maxn],add[2*maxn],sp[lg][maxn];
vector<pii>qrs[maxn];
vector<int>ops[maxn];

int gmx(int l,int r){
	int k=__lg(r-l);
	return max(sp[k][l],sp[k][r-(1<<k)]);
}

void init(int l,int r,int idx){
	add[idx]=0;
	if(l+1==r)dat[idx]=a[l];
	else init(l,mid,lch),init(mid,r,rch),dat[idx]=max(dat[lch],dat[rch]);
}

void ch(int l,int r,int idx,int k){MAX(add[idx],k),MAX(dat[idx],k+gmx(l,r));}

void psh(int l,int r,int idx){ch(l,mid,lch,add[idx]),ch(mid,r,rch,add[idx]);}

void ch(int l,int r,int idx,int a,int b,int k){
	if(b<=l||r<=a)return;
	else if(a<=l&&r<=b)ch(l,r,idx,k);
	else psh(l,r,idx),ch(l,mid,lch,a,b,k),ch(mid,r,rch,a,b,k),dat[idx]=max(dat[lch],dat[rch]);
}

int qr(int l,int r,int idx,int a,int b){
	if(b<=l||r<=a)return 0;
	else if(a<=l&&r<=b)return dat[idx];
	else return psh(l,r,idx),max(qr(l,mid,lch,a,b),qr(mid,r,rch,a,b));
}

main(){
	IOS;
	cin>>n;
	RREP(i,n,0)cin>>a[i],sp[0][i]=a[i];
	REP(i,1,lg)REP(j,0,n)if(j+(1<<i-1)<n)sp[i][j]=max(sp[i-1][j],sp[i-1][j+(1<<i-1)]);
	cin>>q;
	REP(i,0,q){
		int l,r;cin>>r>>l,l=n-l,r=n-r;
		qrs[r].pb({l,i});
	}
	REP(d,0,2){
		stack<int>stk;
		REP(_,0,n){
			int i=d?n-1-_:_;
			while(stk.size()&&a[stk.top()]<a[i])stk.pop();
			if(stk.size())d?ops[stk.top()].pb(i):ops[i].pb(stk.top());
			stk.push(i);
		}
	}
	init(0,n,0);
	REP(i,0,n){
		REP(j,0,ops[i].size()){
			int p=ops[i][j];
			ch(0,n,0,0,2*p-i+1,a[i]+a[p]);
		}
		REP(j,0,qrs[i].size()){
			pii&qq=qrs[i][j];
			res[qq.s]=qr(0,n,0,qq.f,i+1);
		}
	}
	REP(i,0,q)cout<<res[i]<<endl;
}

Compilation message

jumps.cpp: In function 'void init(int, int, int)':
jumps.cpp:11:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define mid (l+r>>1)
              ~^~
jumps.cpp:30:14: note: in expansion of macro 'mid'
  else init(l,mid,lch),init(mid,r,rch),dat[idx]=max(dat[lch],dat[rch]);
              ^~~
jumps.cpp:11:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define mid (l+r>>1)
              ~^~
jumps.cpp:30:28: note: in expansion of macro 'mid'
  else init(l,mid,lch),init(mid,r,rch),dat[idx]=max(dat[lch],dat[rch]);
                            ^~~
jumps.cpp: In function 'void psh(int, int, int)':
jumps.cpp:11:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define mid (l+r>>1)
              ~^~
jumps.cpp:35:36: note: in expansion of macro 'mid'
 void psh(int l,int r,int idx){ch(l,mid,lch,add[idx]),ch(mid,r,rch,add[idx]);}
                                    ^~~
jumps.cpp:11:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define mid (l+r>>1)
              ~^~
jumps.cpp:35:57: note: in expansion of macro 'mid'
 void psh(int l,int r,int idx){ch(l,mid,lch,add[idx]),ch(mid,r,rch,add[idx]);}
                                                         ^~~
jumps.cpp: In function 'void ch(int, int, int, int, int, int)':
jumps.cpp:11:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define mid (l+r>>1)
              ~^~
jumps.cpp:40:25: note: in expansion of macro 'mid'
  else psh(l,r,idx),ch(l,mid,lch,a,b,k),ch(mid,r,rch,a,b,k),dat[idx]=max(dat[lch],dat[rch]);
                         ^~~
jumps.cpp:11:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define mid (l+r>>1)
              ~^~
jumps.cpp:40:43: note: in expansion of macro 'mid'
  else psh(l,r,idx),ch(l,mid,lch,a,b,k),ch(mid,r,rch,a,b,k),dat[idx]=max(dat[lch],dat[rch]);
                                           ^~~
jumps.cpp: In function 'int qr(int, int, int, int, int)':
jumps.cpp:11:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define mid (l+r>>1)
              ~^~
jumps.cpp:46:36: note: in expansion of macro 'mid'
  else return psh(l,r,idx),max(qr(l,mid,lch,a,b),qr(mid,r,rch,a,b));
                                    ^~~
jumps.cpp:11:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define mid (l+r>>1)
              ~^~
jumps.cpp:46:52: note: in expansion of macro 'mid'
  else return psh(l,r,idx),max(qr(l,mid,lch,a,b),qr(mid,r,rch,a,b));
                                                    ^~~
jumps.cpp: At global scope:
jumps.cpp:49:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
jumps.cpp: In function 'int main()':
jumps.cpp:53:33: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
  REP(i,1,lg)REP(j,0,n)if(j+(1<<i-1)<n)sp[i][j]=max(sp[i-1][j],sp[i-1][j+(1<<i-1)]);
                                ~^~
jumps.cpp:53:78: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
  REP(i,1,lg)REP(j,0,n)if(j+(1<<i-1)<n)sp[i][j]=max(sp[i-1][j],sp[i-1][j+(1<<i-1)]);
                                                                             ~^~
jumps.cpp:5:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,j,k) for(int i=(j);i<(k);++i)
                                   ^
jumps.cpp:70:3: note: in expansion of macro 'REP'
   REP(j,0,ops[i].size()){
   ^~~
jumps.cpp:5:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define REP(i,j,k) for(int i=(j);i<(k);++i)
                                   ^
jumps.cpp:74:3: note: in expansion of macro 'REP'
   REP(j,0,qrs[i].size()){
   ^~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 24952 KB Output is correct
2 Correct 27 ms 25080 KB Output is correct
3 Correct 26 ms 25080 KB Output is correct
4 Correct 26 ms 25080 KB Output is correct
5 Correct 31 ms 25080 KB Output is correct
6 Correct 27 ms 25080 KB Output is correct
7 Correct 26 ms 25208 KB Output is correct
8 Correct 26 ms 25080 KB Output is correct
9 Correct 27 ms 25244 KB Output is correct
10 Correct 27 ms 25080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 24952 KB Output is correct
2 Correct 27 ms 25080 KB Output is correct
3 Correct 26 ms 25080 KB Output is correct
4 Correct 26 ms 25080 KB Output is correct
5 Correct 31 ms 25080 KB Output is correct
6 Correct 27 ms 25080 KB Output is correct
7 Correct 26 ms 25208 KB Output is correct
8 Correct 26 ms 25080 KB Output is correct
9 Correct 27 ms 25244 KB Output is correct
10 Correct 27 ms 25080 KB Output is correct
11 Correct 441 ms 43724 KB Output is correct
12 Correct 435 ms 43480 KB Output is correct
13 Correct 458 ms 43572 KB Output is correct
14 Correct 432 ms 43700 KB Output is correct
15 Correct 447 ms 43640 KB Output is correct
16 Correct 441 ms 42940 KB Output is correct
17 Correct 441 ms 42912 KB Output is correct
18 Correct 441 ms 43028 KB Output is correct
19 Correct 442 ms 43476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 52476 KB Output is correct
2 Correct 160 ms 52816 KB Output is correct
3 Correct 159 ms 52700 KB Output is correct
4 Correct 245 ms 52600 KB Output is correct
5 Correct 247 ms 52600 KB Output is correct
6 Correct 240 ms 51820 KB Output is correct
7 Correct 240 ms 51872 KB Output is correct
8 Correct 237 ms 51840 KB Output is correct
9 Correct 240 ms 52060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 24952 KB Output is correct
2 Correct 27 ms 25080 KB Output is correct
3 Correct 26 ms 25080 KB Output is correct
4 Correct 26 ms 25080 KB Output is correct
5 Correct 31 ms 25080 KB Output is correct
6 Correct 27 ms 25080 KB Output is correct
7 Correct 26 ms 25208 KB Output is correct
8 Correct 26 ms 25080 KB Output is correct
9 Correct 27 ms 25244 KB Output is correct
10 Correct 27 ms 25080 KB Output is correct
11 Correct 441 ms 43724 KB Output is correct
12 Correct 435 ms 43480 KB Output is correct
13 Correct 458 ms 43572 KB Output is correct
14 Correct 432 ms 43700 KB Output is correct
15 Correct 447 ms 43640 KB Output is correct
16 Correct 441 ms 42940 KB Output is correct
17 Correct 441 ms 42912 KB Output is correct
18 Correct 441 ms 43028 KB Output is correct
19 Correct 442 ms 43476 KB Output is correct
20 Correct 244 ms 52476 KB Output is correct
21 Correct 160 ms 52816 KB Output is correct
22 Correct 159 ms 52700 KB Output is correct
23 Correct 245 ms 52600 KB Output is correct
24 Correct 247 ms 52600 KB Output is correct
25 Correct 240 ms 51820 KB Output is correct
26 Correct 240 ms 51872 KB Output is correct
27 Correct 237 ms 51840 KB Output is correct
28 Correct 240 ms 52060 KB Output is correct
29 Correct 1669 ms 116484 KB Output is correct
30 Correct 1565 ms 116748 KB Output is correct
31 Correct 1429 ms 116964 KB Output is correct
32 Correct 1666 ms 116472 KB Output is correct
33 Correct 1644 ms 116472 KB Output is correct
34 Correct 1642 ms 114192 KB Output is correct
35 Correct 1637 ms 113828 KB Output is correct
36 Correct 1656 ms 113940 KB Output is correct
37 Correct 1626 ms 115376 KB Output is correct
38 Correct 1104 ms 122268 KB Output is correct
39 Correct 1086 ms 122124 KB Output is correct
40 Correct 1062 ms 118868 KB Output is correct
41 Correct 1055 ms 118488 KB Output is correct
42 Correct 1053 ms 118420 KB Output is correct
43 Correct 1071 ms 120116 KB Output is correct
44 Correct 1170 ms 121628 KB Output is correct
45 Correct 1180 ms 121624 KB Output is correct
46 Correct 1147 ms 118332 KB Output is correct
47 Correct 1149 ms 117996 KB Output is correct
48 Correct 1145 ms 118020 KB Output is correct
49 Correct 1152 ms 120256 KB Output is correct
50 Correct 1303 ms 119408 KB Output is correct
51 Correct 1309 ms 119624 KB Output is correct
52 Correct 1298 ms 116948 KB Output is correct
53 Correct 1281 ms 116544 KB Output is correct
54 Correct 1301 ms 116644 KB Output is correct
55 Correct 1292 ms 118360 KB Output is correct