Submission #414320

# Submission time Handle Problem Language Result Execution time Memory
414320 2021-05-30T10:31:21 Z CSQ31 Triple Jump (JOI19_jumps) C++14
46 / 100
424 ms 41664 KB
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
const int MAXN = 2e5+5;
vector<ll>a(MAXN);
int n,Q;
vector<ll>t(4*MAXN),amx(4*MAXN),lazy(4*MAXN,-INF);
void upd(int v,int l,int r,int tl,int tr,ll val){
	if(l > r)return;
	if(l == tl && tr == r){
		lazy[v] = max(lazy[v],val);
		t[v] = max(t[v],amx[v]+lazy[v]);
		return;
	}
	int tm = (tl+tr)/2;
    upd(2*v,l,min(r,tm),tl,tm,val),
    upd(2*v+1,max(tm+1,l),r,tm+1,tr,val);
	t[v] = max({t[2*v],t[2*v+1],lazy[v]+amx[v]});
}
PII query(int v,int l,int r,int tl,int tr){
	if(l > r)return {0,0};
	if(l == tl && r == tr)return {t[v],amx[v]};
	int tm = (tl+tr)/2;
	PII a = query(2*v,l,min(r,tm),tl,tm);
	PII b = query(2*v+1,max(tm+1,l),r,tm+1,tr);
	PII res;
	res.fi = max({a.fi,b.fi,max(a.se,b.se)+lazy[v]});
	res.se = max(a.se,b.se);
	return res;
}
void build(int v,int l,int r){
	if(l == r){
		amx[v] = a[l];
		return;
	}
	int tm = (l+r)/2;
	build(2*v,l,tm);
	build(2*v+1,tm+1,r);
	amx[v] = max(amx[2*v],amx[2*v+1]);
}
struct que{
	int l,r,idx;
	bool operator<(const que &z){return z.l < l;}
	que(){}
};
int main()
{
	owo
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	cin>>Q;
	vector<que>q(Q);
	vii can(n+1);
	for(int i=0;i<Q;i++){
		cin>>q[i].l>>q[i].r;
		q[i].idx = i;
	}
	stack<pii>stk;
	build(1,1,n);
	for(int i=1;i<=n;i++){
		while(!stk.empty() && stk.top().fi < a[i])stk.pop();
		if(!stk.empty())can[stk.top().se].pb(i);
		stk.push({a[i],i});
	}
	while(!stk.empty())stk.pop();
	for(int i=n;i;i--){
		while(!stk.empty() && stk.top().fi < a[i])stk.pop();
		if(!stk.empty())can[i].pb(stk.top().se);
		stk.push({a[i],i});
	}
	vector<ll>ans(Q);
	int ptr = 0;
	sort(all(q));
	for(int i=n;i>0;i--){
		int st = ptr;
		while(ptr<sz(q) && q[ptr].l >= i)ptr++;
		for(int x:can[i]){
			int rg = 2*x-i;
			if(rg<=n)upd(1,rg,n,1,n,a[i]+a[x]);
		}
		for(int j=st;j<ptr;j++){
			ans[q[j].idx] = query(1,q[j].l,q[j].r,1,n).fi;
		}
	}
	for(int i=0;i<Q;i++)cout<<ans[i]<<'\n';
	
}
/*
5
5 2 1 5 3
3
1 4
2 5
1 5
*/
# Verdict Execution time Memory Grader output
1 Correct 11 ms 20556 KB Output is correct
2 Correct 11 ms 20632 KB Output is correct
3 Correct 11 ms 20556 KB Output is correct
4 Correct 11 ms 20576 KB Output is correct
5 Correct 12 ms 20576 KB Output is correct
6 Correct 11 ms 20684 KB Output is correct
7 Correct 11 ms 20684 KB Output is correct
8 Correct 11 ms 20556 KB Output is correct
9 Correct 11 ms 20616 KB Output is correct
10 Correct 11 ms 20684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 20556 KB Output is correct
2 Correct 11 ms 20632 KB Output is correct
3 Correct 11 ms 20556 KB Output is correct
4 Correct 11 ms 20576 KB Output is correct
5 Correct 12 ms 20576 KB Output is correct
6 Correct 11 ms 20684 KB Output is correct
7 Correct 11 ms 20684 KB Output is correct
8 Correct 11 ms 20556 KB Output is correct
9 Correct 11 ms 20616 KB Output is correct
10 Correct 11 ms 20684 KB Output is correct
11 Correct 360 ms 35724 KB Output is correct
12 Correct 365 ms 35864 KB Output is correct
13 Correct 356 ms 35780 KB Output is correct
14 Correct 424 ms 35728 KB Output is correct
15 Correct 356 ms 35776 KB Output is correct
16 Correct 359 ms 34984 KB Output is correct
17 Correct 366 ms 35012 KB Output is correct
18 Correct 363 ms 35012 KB Output is correct
19 Correct 386 ms 35636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 175 ms 31812 KB Output is correct
2 Correct 110 ms 33220 KB Output is correct
3 Correct 128 ms 33192 KB Output is correct
4 Correct 191 ms 31840 KB Output is correct
5 Correct 178 ms 31992 KB Output is correct
6 Correct 176 ms 31940 KB Output is correct
7 Correct 173 ms 31816 KB Output is correct
8 Correct 176 ms 31868 KB Output is correct
9 Correct 172 ms 31808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 20556 KB Output is correct
2 Correct 11 ms 20632 KB Output is correct
3 Correct 11 ms 20556 KB Output is correct
4 Correct 11 ms 20576 KB Output is correct
5 Correct 12 ms 20576 KB Output is correct
6 Correct 11 ms 20684 KB Output is correct
7 Correct 11 ms 20684 KB Output is correct
8 Correct 11 ms 20556 KB Output is correct
9 Correct 11 ms 20616 KB Output is correct
10 Correct 11 ms 20684 KB Output is correct
11 Correct 360 ms 35724 KB Output is correct
12 Correct 365 ms 35864 KB Output is correct
13 Correct 356 ms 35780 KB Output is correct
14 Correct 424 ms 35728 KB Output is correct
15 Correct 356 ms 35776 KB Output is correct
16 Correct 359 ms 34984 KB Output is correct
17 Correct 366 ms 35012 KB Output is correct
18 Correct 363 ms 35012 KB Output is correct
19 Correct 386 ms 35636 KB Output is correct
20 Correct 175 ms 31812 KB Output is correct
21 Correct 110 ms 33220 KB Output is correct
22 Correct 128 ms 33192 KB Output is correct
23 Correct 191 ms 31840 KB Output is correct
24 Correct 178 ms 31992 KB Output is correct
25 Correct 176 ms 31940 KB Output is correct
26 Correct 173 ms 31816 KB Output is correct
27 Correct 176 ms 31868 KB Output is correct
28 Correct 172 ms 31808 KB Output is correct
29 Runtime error 55 ms 41664 KB Execution killed with signal 11
30 Halted 0 ms 0 KB -