Submission #518111

# Submission time Handle Problem Language Result Execution time Memory
518111 2022-01-23T08:39:47 Z Koosha_mv Constellation 3 (JOI20_constellation3) C++14
100 / 100
612 ms 60032 KB
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
 
const int N=3e5+99;
 
int n,m,sum,ans,a[N],x[N],y[N],L[N],R[N],val[N],dp[N],par[N],fenwik[N];
vector<int> g[N],vec[N];
pair<int,int> p[N];
pair<pair<int,int>,int> c[N];
 
void add(int x, int val){ for(x++;x<N;x+=x&-x) fenwik[x]+=val; }
int get(int x) { int res=0; for (x++;x>0;x-=x&-x) res+=fenwik[x]; return res; }

bool cmp(int i,int j){
	return R[i]<R[j];
}
void findlr(){
	vector<int> v;
	int now=1;
	a[0]=-1,a[n+1]=-1;
	v.pb(0);
	f(i,0,m){
		while(now<=p[i].F){
			while(a[now]<=a[v.back()]){
				v.pop_back();
			}
			v.pb(now);
			now++;
		}
		int l=0,r=v.size();
		while(l+1<r){
			int mid=(l+r)>>1;
			if(a[v[mid]]<p[i].S) l=mid;
			else r=mid;
		}
		L[i]=v[l]+1;
		vec[L[i]].pb(i);
	}
	v.clear();
	v.pb(n+1);
	now=n;
	f_(i,m-1,0){
		while(now>=p[i].F){
			while(a[now]<=a[v.back()]){
				v.pop_back();
			}
			v.pb(now);
			now--;
		}
		int l=0,r=v.size();
		while(l+1<r){
			int mid=(l+r)>>1;
			if(a[v[mid]]<p[i].S) l=mid;
			else r=mid;
		}
		R[i]=v[l]-1;
	}
}
bool contain(int id,int x){
	return L[id]<=x && x<=R[id];
}
void dfs(int u){
	int sum=val[u];
	for(auto v : g[u]){
		dfs(v);
		dp[u]+=dp[v];
	}
	for(auto v : g[u]){
		add(L[u],dp[v]);
		add(L[v],-dp[v]);
		add(R[v]+1,dp[v]);
		add(R[u]+1,-dp[v]);
	}
	maxm(dp[u],val[u]+get(p[u].F));
}
void buildgraph(){
	vector<int> v;
	f_(i,n,1){
		sort(all(vec[i]),cmp);
		for(auto id : vec[i]){
			while(v.size() && R[v.back()]<=R[id]){
				par[v.back()]=id;
				g[id].pb(v.back());
				v.pop_back();
			}
			v.pb(id);
		}
	}
	for(auto id : v){
		dfs(id);
		ans+=dp[id];
	}
}
 
main(){
	cin>>n;
	f(i,1,n+1){
		cin>>a[i];
		a[i]=n-a[i];
	}
	cin>>m;
	f(i,0,m){
		cin>>c[i].F.F>>c[i].F.S>>c[i].S;
		c[i].F.S=n+1-c[i].F.S;
	}
	sort(c,c+m);
	f(i,0,m){
		val[i]=c[i].S;
		p[i].F=c[i].F.F;
		p[i].S=c[i].F.S;
		sum+=val[i];
	}
	findlr();
	buildgraph();
	cout<<sum-ans;
}

Compilation message

constellation3.cpp: In function 'void dfs(long long int)':
constellation3.cpp:83:6: warning: unused variable 'sum' [-Wunused-variable]
   83 |  int sum=val[u];
      |      ^~~
constellation3.cpp: At global scope:
constellation3.cpp:115:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  115 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14540 KB Output is correct
2 Correct 8 ms 14428 KB Output is correct
3 Correct 9 ms 14580 KB Output is correct
4 Correct 12 ms 14496 KB Output is correct
5 Correct 9 ms 14544 KB Output is correct
6 Correct 10 ms 14544 KB Output is correct
7 Correct 12 ms 14532 KB Output is correct
8 Correct 13 ms 14544 KB Output is correct
9 Correct 13 ms 14544 KB Output is correct
10 Correct 11 ms 14544 KB Output is correct
11 Correct 12 ms 14544 KB Output is correct
12 Correct 9 ms 14544 KB Output is correct
13 Correct 9 ms 14532 KB Output is correct
14 Correct 8 ms 14544 KB Output is correct
15 Correct 12 ms 14544 KB Output is correct
16 Correct 9 ms 14540 KB Output is correct
17 Correct 8 ms 14544 KB Output is correct
18 Correct 10 ms 14536 KB Output is correct
19 Correct 9 ms 14532 KB Output is correct
20 Correct 9 ms 14544 KB Output is correct
21 Correct 11 ms 14492 KB Output is correct
22 Correct 11 ms 14532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14540 KB Output is correct
2 Correct 8 ms 14428 KB Output is correct
3 Correct 9 ms 14580 KB Output is correct
4 Correct 12 ms 14496 KB Output is correct
5 Correct 9 ms 14544 KB Output is correct
6 Correct 10 ms 14544 KB Output is correct
7 Correct 12 ms 14532 KB Output is correct
8 Correct 13 ms 14544 KB Output is correct
9 Correct 13 ms 14544 KB Output is correct
10 Correct 11 ms 14544 KB Output is correct
11 Correct 12 ms 14544 KB Output is correct
12 Correct 9 ms 14544 KB Output is correct
13 Correct 9 ms 14532 KB Output is correct
14 Correct 8 ms 14544 KB Output is correct
15 Correct 12 ms 14544 KB Output is correct
16 Correct 9 ms 14540 KB Output is correct
17 Correct 8 ms 14544 KB Output is correct
18 Correct 10 ms 14536 KB Output is correct
19 Correct 9 ms 14532 KB Output is correct
20 Correct 9 ms 14544 KB Output is correct
21 Correct 11 ms 14492 KB Output is correct
22 Correct 11 ms 14532 KB Output is correct
23 Correct 15 ms 14672 KB Output is correct
24 Correct 12 ms 14804 KB Output is correct
25 Correct 10 ms 14672 KB Output is correct
26 Correct 11 ms 14800 KB Output is correct
27 Correct 11 ms 14728 KB Output is correct
28 Correct 12 ms 14824 KB Output is correct
29 Correct 11 ms 14672 KB Output is correct
30 Correct 11 ms 14724 KB Output is correct
31 Correct 11 ms 14804 KB Output is correct
32 Correct 11 ms 14800 KB Output is correct
33 Correct 17 ms 14948 KB Output is correct
34 Correct 15 ms 14900 KB Output is correct
35 Correct 15 ms 14860 KB Output is correct
36 Correct 11 ms 14796 KB Output is correct
37 Correct 11 ms 14800 KB Output is correct
38 Correct 11 ms 14796 KB Output is correct
39 Correct 12 ms 14720 KB Output is correct
40 Correct 12 ms 14884 KB Output is correct
41 Correct 10 ms 14800 KB Output is correct
42 Correct 14 ms 14820 KB Output is correct
43 Correct 10 ms 14928 KB Output is correct
44 Correct 12 ms 14828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 14540 KB Output is correct
2 Correct 8 ms 14428 KB Output is correct
3 Correct 9 ms 14580 KB Output is correct
4 Correct 12 ms 14496 KB Output is correct
5 Correct 9 ms 14544 KB Output is correct
6 Correct 10 ms 14544 KB Output is correct
7 Correct 12 ms 14532 KB Output is correct
8 Correct 13 ms 14544 KB Output is correct
9 Correct 13 ms 14544 KB Output is correct
10 Correct 11 ms 14544 KB Output is correct
11 Correct 12 ms 14544 KB Output is correct
12 Correct 9 ms 14544 KB Output is correct
13 Correct 9 ms 14532 KB Output is correct
14 Correct 8 ms 14544 KB Output is correct
15 Correct 12 ms 14544 KB Output is correct
16 Correct 9 ms 14540 KB Output is correct
17 Correct 8 ms 14544 KB Output is correct
18 Correct 10 ms 14536 KB Output is correct
19 Correct 9 ms 14532 KB Output is correct
20 Correct 9 ms 14544 KB Output is correct
21 Correct 11 ms 14492 KB Output is correct
22 Correct 11 ms 14532 KB Output is correct
23 Correct 15 ms 14672 KB Output is correct
24 Correct 12 ms 14804 KB Output is correct
25 Correct 10 ms 14672 KB Output is correct
26 Correct 11 ms 14800 KB Output is correct
27 Correct 11 ms 14728 KB Output is correct
28 Correct 12 ms 14824 KB Output is correct
29 Correct 11 ms 14672 KB Output is correct
30 Correct 11 ms 14724 KB Output is correct
31 Correct 11 ms 14804 KB Output is correct
32 Correct 11 ms 14800 KB Output is correct
33 Correct 17 ms 14948 KB Output is correct
34 Correct 15 ms 14900 KB Output is correct
35 Correct 15 ms 14860 KB Output is correct
36 Correct 11 ms 14796 KB Output is correct
37 Correct 11 ms 14800 KB Output is correct
38 Correct 11 ms 14796 KB Output is correct
39 Correct 12 ms 14720 KB Output is correct
40 Correct 12 ms 14884 KB Output is correct
41 Correct 10 ms 14800 KB Output is correct
42 Correct 14 ms 14820 KB Output is correct
43 Correct 10 ms 14928 KB Output is correct
44 Correct 12 ms 14828 KB Output is correct
45 Correct 367 ms 46524 KB Output is correct
46 Correct 370 ms 45796 KB Output is correct
47 Correct 338 ms 46992 KB Output is correct
48 Correct 404 ms 45708 KB Output is correct
49 Correct 488 ms 46056 KB Output is correct
50 Correct 337 ms 45604 KB Output is correct
51 Correct 399 ms 46308 KB Output is correct
52 Correct 374 ms 46840 KB Output is correct
53 Correct 468 ms 45880 KB Output is correct
54 Correct 499 ms 60032 KB Output is correct
55 Correct 612 ms 59828 KB Output is correct
56 Correct 498 ms 59132 KB Output is correct
57 Correct 478 ms 59360 KB Output is correct
58 Correct 421 ms 58020 KB Output is correct
59 Correct 389 ms 58568 KB Output is correct
60 Correct 327 ms 57312 KB Output is correct
61 Correct 386 ms 48044 KB Output is correct
62 Correct 573 ms 59664 KB Output is correct
63 Correct 355 ms 48624 KB Output is correct
64 Correct 423 ms 47128 KB Output is correct
65 Correct 524 ms 58500 KB Output is correct
66 Correct 329 ms 49676 KB Output is correct