Submission #944290

# Submission time Handle Problem Language Result Execution time Memory
944290 2024-03-12T14:14:32 Z beepbeepsheep Triple Jump (JOI19_jumps) C++17
100 / 100
794 ms 137532 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<long long, null_type, less_equal<>,
        rb_tree_tag, tree_order_statistics_node_update>
        ordered_set;
        
#define ll long long
#define ii pair<ll,ll>
#define iii tuple<ll,ll,ll>

#ifndef DEBUG
#define cerr if (0) cerr
#define endl '\n'
#endif

const ll inf=1e15;
const ll maxn=5e5+5;
const ll mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

ll arr[maxn];
stack<ll> s;
vector<ii> v;
struct node{
	ll s,e,m,ab,c,abc;
	node *l, *r;
	node(ll _s, ll _e){
		s=_s,e=_e,m=(s+e)>>1,ab=-inf,c=-inf,abc=2*-inf;
		if (s!=e) l=new node(s,m),r=new node(m+1,e);
	}
	void upd(ll x, ll v, ll type){
		if (s==e){
			if (type==1){
				ab=max(ab,v);
			} else c=max(c,v);
			abc=ab+c;
			return;
		}
		if (x>m) r->upd(x,v,type);
		else l->upd(x,v,type);
		ab=max(l->ab,r->ab),c=max(l->c,r->c);
		abc=max({l->abc,r->abc,l->ab+r->c});
	}
	ll query(ll x, ll y){
		iii t=process(x,y);
		return get<2>(t);
	}
	iii process(ll x, ll y){
		if (x<=s && e<=y) return {ab,c,abc};
		if (x>m) return r->process(x,y);
		if (y<=m) return l->process(x,y);
		ll lab,lc,labc,rab,rc,rabc;
		tie(lab,lc,labc)=l->process(x,y);
		tie(rab,rc,rabc)=r->process(x,y);
		iii t={max(lab,rab),max(lc,rc),max({labc,rabc,lab+rc})};
		return t;
	}
}*root;
ll ans[maxn];
vector<iii> q;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin>>n;
	root=new node(1,n);
	for (int i=1;i<=n;i++){
		cin>>arr[i];
		root->upd(i,arr[i],2);
	}
	for (int i=1;i<=n;i++){
		while (s.size() && arr[s.top()]<=arr[i]){
			if (2*i-s.top()<=n) //check that it is in range
				v.emplace_back(s.top(),i);
			s.pop();
		}
		if (s.size()){
			if (2*i-s.top()<=n)
				v.emplace_back(s.top(),i);
		}
		s.emplace(i);
	}
	sort(v.rbegin(),v.rend());
	ll qu,l,r;
	cin>>qu;
	for (int i=1;i<=qu;i++){
		cin>>l>>r;
		q.emplace_back(l,r,i);
	}
	sort(q.rbegin(),q.rend());
	ll ptr=0;
	for (auto [l,r,idx]:q){
		cerr<<l<<' '<<r<<'x'<<endl;
		while (ptr!=v.size() && l<=v[ptr].first){
			ll a,b;
			tie(a,b)=v[ptr];
			cerr<<a<<' '<<b<<endl;
			root->upd(2*b-a,arr[a]+arr[b],1);
			ptr++;
		}
		ans[idx]=root->query(1,r);
	}
	for (int i=1;i<=qu;i++) cout<<ans[i]<<endl;
	return 0;
}

Compilation message

jumps.cpp: In function 'int main()':
jumps.cpp:99:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |   while (ptr!=v.size() && l<=v[ptr].first){
      |          ~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 191 ms 25588 KB Output is correct
12 Correct 193 ms 25080 KB Output is correct
13 Correct 189 ms 25116 KB Output is correct
14 Correct 185 ms 25584 KB Output is correct
15 Correct 192 ms 25188 KB Output is correct
16 Correct 222 ms 24484 KB Output is correct
17 Correct 190 ms 24872 KB Output is correct
18 Correct 189 ms 24452 KB Output is correct
19 Correct 190 ms 24900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 44392 KB Output is correct
2 Correct 90 ms 40644 KB Output is correct
3 Correct 89 ms 41352 KB Output is correct
4 Correct 127 ms 45444 KB Output is correct
5 Correct 136 ms 44940 KB Output is correct
6 Correct 128 ms 44228 KB Output is correct
7 Correct 126 ms 45664 KB Output is correct
8 Correct 127 ms 44948 KB Output is correct
9 Correct 138 ms 44580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 191 ms 25588 KB Output is correct
12 Correct 193 ms 25080 KB Output is correct
13 Correct 189 ms 25116 KB Output is correct
14 Correct 185 ms 25584 KB Output is correct
15 Correct 192 ms 25188 KB Output is correct
16 Correct 222 ms 24484 KB Output is correct
17 Correct 190 ms 24872 KB Output is correct
18 Correct 189 ms 24452 KB Output is correct
19 Correct 190 ms 24900 KB Output is correct
20 Correct 130 ms 44392 KB Output is correct
21 Correct 90 ms 40644 KB Output is correct
22 Correct 89 ms 41352 KB Output is correct
23 Correct 127 ms 45444 KB Output is correct
24 Correct 136 ms 44940 KB Output is correct
25 Correct 128 ms 44228 KB Output is correct
26 Correct 126 ms 45664 KB Output is correct
27 Correct 127 ms 44948 KB Output is correct
28 Correct 138 ms 44580 KB Output is correct
29 Correct 791 ms 136888 KB Output is correct
30 Correct 636 ms 122808 KB Output is correct
31 Correct 651 ms 127048 KB Output is correct
32 Correct 731 ms 137152 KB Output is correct
33 Correct 757 ms 136884 KB Output is correct
34 Correct 791 ms 135492 KB Output is correct
35 Correct 735 ms 135852 KB Output is correct
36 Correct 794 ms 135620 KB Output is correct
37 Correct 728 ms 136272 KB Output is correct
38 Correct 561 ms 137508 KB Output is correct
39 Correct 526 ms 136788 KB Output is correct
40 Correct 522 ms 134684 KB Output is correct
41 Correct 528 ms 134004 KB Output is correct
42 Correct 553 ms 134236 KB Output is correct
43 Correct 537 ms 135256 KB Output is correct
44 Correct 535 ms 137532 KB Output is correct
45 Correct 549 ms 131744 KB Output is correct
46 Correct 526 ms 130228 KB Output is correct
47 Correct 543 ms 129608 KB Output is correct
48 Correct 523 ms 129452 KB Output is correct
49 Correct 529 ms 130972 KB Output is correct
50 Correct 579 ms 131304 KB Output is correct
51 Correct 577 ms 131380 KB Output is correct
52 Correct 572 ms 130320 KB Output is correct
53 Correct 615 ms 130960 KB Output is correct
54 Correct 586 ms 130364 KB Output is correct
55 Correct 576 ms 130988 KB Output is correct