답안 #446279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446279 2021-07-21T12:31:48 Z cheetose 별자리 3 (JOI20_constellation3) C++17
100 / 100
306 ms 68964 KB
#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

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);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10572 KB Output is correct
2 Correct 7 ms 10444 KB Output is correct
3 Correct 6 ms 10496 KB Output is correct
4 Correct 7 ms 10492 KB Output is correct
5 Correct 7 ms 10572 KB Output is correct
6 Correct 8 ms 10444 KB Output is correct
7 Correct 7 ms 10444 KB Output is correct
8 Correct 7 ms 10572 KB Output is correct
9 Correct 7 ms 10468 KB Output is correct
10 Correct 7 ms 10572 KB Output is correct
11 Correct 7 ms 10572 KB Output is correct
12 Correct 7 ms 10484 KB Output is correct
13 Correct 7 ms 10516 KB Output is correct
14 Correct 7 ms 10444 KB Output is correct
15 Correct 7 ms 10444 KB Output is correct
16 Correct 7 ms 10572 KB Output is correct
17 Correct 7 ms 10492 KB Output is correct
18 Correct 8 ms 10504 KB Output is correct
19 Correct 7 ms 10552 KB Output is correct
20 Correct 7 ms 10444 KB Output is correct
21 Correct 7 ms 10572 KB Output is correct
22 Correct 8 ms 10492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10572 KB Output is correct
2 Correct 7 ms 10444 KB Output is correct
3 Correct 6 ms 10496 KB Output is correct
4 Correct 7 ms 10492 KB Output is correct
5 Correct 7 ms 10572 KB Output is correct
6 Correct 8 ms 10444 KB Output is correct
7 Correct 7 ms 10444 KB Output is correct
8 Correct 7 ms 10572 KB Output is correct
9 Correct 7 ms 10468 KB Output is correct
10 Correct 7 ms 10572 KB Output is correct
11 Correct 7 ms 10572 KB Output is correct
12 Correct 7 ms 10484 KB Output is correct
13 Correct 7 ms 10516 KB Output is correct
14 Correct 7 ms 10444 KB Output is correct
15 Correct 7 ms 10444 KB Output is correct
16 Correct 7 ms 10572 KB Output is correct
17 Correct 7 ms 10492 KB Output is correct
18 Correct 8 ms 10504 KB Output is correct
19 Correct 7 ms 10552 KB Output is correct
20 Correct 7 ms 10444 KB Output is correct
21 Correct 7 ms 10572 KB Output is correct
22 Correct 8 ms 10492 KB Output is correct
23 Correct 8 ms 10700 KB Output is correct
24 Correct 8 ms 10700 KB Output is correct
25 Correct 9 ms 10796 KB Output is correct
26 Correct 8 ms 10696 KB Output is correct
27 Correct 9 ms 10720 KB Output is correct
28 Correct 10 ms 10700 KB Output is correct
29 Correct 8 ms 10756 KB Output is correct
30 Correct 8 ms 10700 KB Output is correct
31 Correct 8 ms 10700 KB Output is correct
32 Correct 9 ms 10956 KB Output is correct
33 Correct 11 ms 10920 KB Output is correct
34 Correct 9 ms 10828 KB Output is correct
35 Correct 10 ms 10888 KB Output is correct
36 Correct 8 ms 10700 KB Output is correct
37 Correct 8 ms 10700 KB Output is correct
38 Correct 8 ms 10956 KB Output is correct
39 Correct 8 ms 10828 KB Output is correct
40 Correct 9 ms 10956 KB Output is correct
41 Correct 8 ms 10700 KB Output is correct
42 Correct 8 ms 10756 KB Output is correct
43 Correct 9 ms 10884 KB Output is correct
44 Correct 10 ms 10700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 10572 KB Output is correct
2 Correct 7 ms 10444 KB Output is correct
3 Correct 6 ms 10496 KB Output is correct
4 Correct 7 ms 10492 KB Output is correct
5 Correct 7 ms 10572 KB Output is correct
6 Correct 8 ms 10444 KB Output is correct
7 Correct 7 ms 10444 KB Output is correct
8 Correct 7 ms 10572 KB Output is correct
9 Correct 7 ms 10468 KB Output is correct
10 Correct 7 ms 10572 KB Output is correct
11 Correct 7 ms 10572 KB Output is correct
12 Correct 7 ms 10484 KB Output is correct
13 Correct 7 ms 10516 KB Output is correct
14 Correct 7 ms 10444 KB Output is correct
15 Correct 7 ms 10444 KB Output is correct
16 Correct 7 ms 10572 KB Output is correct
17 Correct 7 ms 10492 KB Output is correct
18 Correct 8 ms 10504 KB Output is correct
19 Correct 7 ms 10552 KB Output is correct
20 Correct 7 ms 10444 KB Output is correct
21 Correct 7 ms 10572 KB Output is correct
22 Correct 8 ms 10492 KB Output is correct
23 Correct 8 ms 10700 KB Output is correct
24 Correct 8 ms 10700 KB Output is correct
25 Correct 9 ms 10796 KB Output is correct
26 Correct 8 ms 10696 KB Output is correct
27 Correct 9 ms 10720 KB Output is correct
28 Correct 10 ms 10700 KB Output is correct
29 Correct 8 ms 10756 KB Output is correct
30 Correct 8 ms 10700 KB Output is correct
31 Correct 8 ms 10700 KB Output is correct
32 Correct 9 ms 10956 KB Output is correct
33 Correct 11 ms 10920 KB Output is correct
34 Correct 9 ms 10828 KB Output is correct
35 Correct 10 ms 10888 KB Output is correct
36 Correct 8 ms 10700 KB Output is correct
37 Correct 8 ms 10700 KB Output is correct
38 Correct 8 ms 10956 KB Output is correct
39 Correct 8 ms 10828 KB Output is correct
40 Correct 9 ms 10956 KB Output is correct
41 Correct 8 ms 10700 KB Output is correct
42 Correct 8 ms 10756 KB Output is correct
43 Correct 9 ms 10884 KB Output is correct
44 Correct 10 ms 10700 KB Output is correct
45 Correct 289 ms 40432 KB Output is correct
46 Correct 294 ms 40276 KB Output is correct
47 Correct 276 ms 39964 KB Output is correct
48 Correct 276 ms 40392 KB Output is correct
49 Correct 306 ms 39728 KB Output is correct
50 Correct 261 ms 39600 KB Output is correct
51 Correct 293 ms 39716 KB Output is correct
52 Correct 306 ms 40316 KB Output is correct
53 Correct 295 ms 40228 KB Output is correct
54 Correct 286 ms 62672 KB Output is correct
55 Correct 303 ms 57100 KB Output is correct
56 Correct 262 ms 53956 KB Output is correct
57 Correct 260 ms 52044 KB Output is correct
58 Correct 212 ms 38000 KB Output is correct
59 Correct 213 ms 38148 KB Output is correct
60 Correct 188 ms 68964 KB Output is correct
61 Correct 234 ms 37440 KB Output is correct
62 Correct 285 ms 59124 KB Output is correct
63 Correct 274 ms 37228 KB Output is correct
64 Correct 252 ms 36624 KB Output is correct
65 Correct 288 ms 59660 KB Output is correct
66 Correct 257 ms 37216 KB Output is correct