Submission #446279

#TimeUsernameProblemLanguageResultExecution timeMemory
446279cheetoseConstellation 3 (JOI20_constellation3)C++17
100 / 100
306 ms68964 KiB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define COMPRESS(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin())
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<ld> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

int a[200005];
VPi yy[200005];
Vi v[200005];
int lg[200005],d[200005][18];
int mn(int l,int r){
	int k=lg[r-l+1];
	return min(d[l][k],d[r-(1<<k)+1][k]);
}
priority_queue<pair<int,Pi>> q;
ll tree[200005];
void upd(int i, int k){
	while (i <= 200000){
		tree[i] += k;
		i += (i&-i);
	}
}
ll sum(int i){
	ll c = 0;
	while (i > 0){
		c += tree[i];
		i -= (i&-i);
	}
	return c;
}
ll dfs(int l,int r,int k){
	if(l>r)return 0;
	int m=mn(l,r);
	ll ret=0;
	int pr=l;
	for(auto it=lower_bound(ALL(v[m]),l);it!=v[m].end() && *it<=r;it++){
		ret+=dfs(pr,*it-1,m);
		pr=*it+1;
	}
	ret+=dfs(pr,r,m);
	for(auto it=lower_bound(ALL(v[m]),l);it!=v[m].end() && *it<=r;it++){
		int y=*it;
		while(!yy[y].empty()){
			auto [x,c]=yy[y].back();
			q.push(mp(x,mp(y,c)));
			yy[y].pop_back();
		}
	}
	ll res=ret;
	while(!q.empty() && q.top().X>k){
		auto [y,c]=q.top().Y;
		q.pop();
		res=max(res,ret+c-sum(y));
	}
	upd(l,res-ret);
	upd(r+1,ret-res);
	return res;
}
int main(){
	fup(i,1,17,1)lg[1<<i]=i;
	fup(i,2,200000,1)if(!lg[i])lg[i]=lg[i-1];
	int n,m;
	scanf("%d",&n);
	fup(i,1,n,1){
		scanf("%d",a+i);
		a[i]=n-a[i]+1;
		d[i][0]=a[i];
		v[a[i]].pb(i);
	}
	fup(j,0,16,1){
		fup(i,1,n,1){
			if(i+(1<<(j+1))>n+1)break;
			d[i][j+1]=min(d[i][j],d[i+(1<<j)][j]);
		}
	}
	ll sum=0;
	scanf("%d",&m);
	fup(i,0,m-1,1){
		int x,y,z;
		scanf("%d%d%d",&y,&x,&z);
		sum+=z;
		x=n+2-x;
		yy[y].pb(mp(x,z));
	}
	printf("%lld\n",sum-dfs(1,n,0));
}

Compilation message (stderr)

constellation3.cpp: In function 'int main()':
constellation3.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
constellation3.cpp:96:2: note: in expansion of macro 'fup'
   96 |  fup(i,1,17,1)lg[1<<i]=i;
      |  ^~~
constellation3.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
constellation3.cpp:97:2: note: in expansion of macro 'fup'
   97 |  fup(i,2,200000,1)if(!lg[i])lg[i]=lg[i-1];
      |  ^~~
constellation3.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
constellation3.cpp:100:2: note: in expansion of macro 'fup'
  100 |  fup(i,1,n,1){
      |  ^~~
constellation3.cpp:10:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
constellation3.cpp:106:2: note: in expansion of macro 'fup'
  106 |  fup(j,0,16,1){
      |  ^~~
constellation3.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
constellation3.cpp:107:3: note: in expansion of macro 'fup'
  107 |   fup(i,1,n,1){
      |   ^~~
constellation3.cpp:10:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   10 | #define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
      |                              ^
constellation3.cpp:114:2: note: in expansion of macro 'fup'
  114 |  fup(i,0,m-1,1){
      |  ^~~
constellation3.cpp:99:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
constellation3.cpp:101:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |   scanf("%d",a+i);
      |   ~~~~~^~~~~~~~~~
constellation3.cpp:113:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |  scanf("%d",&m);
      |  ~~~~~^~~~~~~~~
constellation3.cpp:116:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |   scanf("%d%d%d",&y,&x,&z);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...