답안 #756676

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
756676 2023-06-12T04:29:45 Z jamezzz Tortoise (CEOI21_tortoise) C++17
18 / 100
4 ms 4328 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define psf push_front
#define ppb pop_back
#define ppf pop_front
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(),x.end()
#define lb(x,v) (lower_bound(all(x),v)-x.begin())
#define ub(x,v) (upper_bound(all(x),v)-x.begin())
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> iii;
typedef tuple<int,int,int,int> iiii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
mt19937 rng(time(0));
 
#define mod 1000000007
 
inline int add(int a,int b){
	int r=a+b;
	while(r>=mod)r-=mod;
	while(r<0)r+=mod;
	return r;
}
 
inline int mult(int a,int b){
	return (int)(((ll)(a*b))%mod);
}
 
inline int rd(){
	int x=0;
	char ch=getchar_unlocked();
	while(!(ch&16))ch=getchar_unlocked();//keep reading while current character is whitespace
	while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
		x=(x<<3)+(x<<1)+(ch&15);
		ch=getchar_unlocked();
	}
	return x;
}
 
#define maxn 500005
 
struct node{
	int s,e,m,v,lz,mn;
	node *l,*r;
	node(int _s,int _e){
		s=_s,e=_e,m=(s+e)>>1,mn=INF,v=0,lz=0;
		if(s!=e)l=new node(s,m),r=new node(m+1,e);
	}
	void ppo(){
		v+=lz;mn+=lz;
		if(s!=e&&lz)l->lz+=lz,r->lz+=lz;
		lz=0;
	}
	void up(int x,int y,int nv){
		if(s==x&&e==y){lz+=nv;return;}
		if(y<=m)l->up(x,y,nv);
		else if(x>m)r->up(x,y,nv);
		else l->up(x,m,nv),r->up(m+1,y,nv);
		l->ppo(),r->ppo();
		mn=min(l->mn,r->mn);
	}
	void set(int x){
		if(s==x&&e==x){mn=v;return;}
		if(x<=m)l->set(x);
		else r->set(x);
		l->ppo(),r->ppo();
		mn=min(l->mn,r->mn);
	}
	int qmn(int x,int y){
		ppo();
		if(s==x&&e==y)return mn;
		if(y<=m)return l->qmn(x,y);
		if(x>m)return r->qmn(x,y);
		return min(l->qmn(x,m),r->qmn(m+1,y));
	}
	int qry(int x){
		ppo();
		if(s==x&&e==x)return v;
		if(x<=m)return l->qry(x);
		else return r->qry(x);
	}
}*rt;
 
int n,a[maxn],d[maxn],mx[maxn],bad[maxn],pv[maxn];
set<ii> s;
ll ans;
vi play,shop;
 
main(){
	sf("%lld",&n);
	rt=new node(0,n-1);
	for(int i=0;i<n;++i){
		sf("%lld",&a[i]);
		if(a[i]==-1){
			play.pb(i);
			rt->up(i,i,INF);
		}
		else{
			shop.pb(i);
			ans+=a[i];
			rt->up(i,i,i);
		}
	}
	int ptr=-1;
	memset(mx,-1,sizeof mx);
	for(int i=0;i<sz(shop);++i){
		while(ptr+1<sz(play)&&play[ptr+1]<shop[i])++ptr;
		int x=shop[i];
		pv[x]=ptr;
		if(a[x]==0)continue;
		d[x]=INF;
		if(ptr!=-1)d[x]=min(d[x],shop[i]-play[ptr]);
		if(ptr+1<sz(play))d[x]=min(d[x],play[ptr+1]-shop[i]);
		if(mx[ptr+1]==-1||d[x]>d[mx[ptr+1]]||(d[x]==d[mx[ptr+1]]&&x>mx[ptr+1]))mx[ptr+1]=x;
		s.insert({d[x],x});
	}
	for(int i=-1;i<sz(play)-1;++i){
		if(mx[i+1]==-1)continue;
		int x=mx[i+1];
		if(a[x]==0)continue;
		rt->set(x);
		--ans;--a[x];
		bad[x]=1;
		//pf("walk %d\n",x);
		if(a[x]==0)s.erase(s.find({d[x],x}));
	}
	while(!s.empty()){
		auto[_,i]=*s.begin();
		s.erase(s.begin());
		//printf("now: %d\n",i);
		int cur=rt->qry(i);
		if(cur<0)continue;
		//pf("pv %d, mx %d, %d\n",pv[i],mx[pv[i]+1],pv[i]==play.size()-1||i<mx[pv[i]+1]);
		int num=min(a[i],cur/(2*d[i])+(pv[i]==play.size()-1||i<mx[pv[i]+1]));
		
		int mn=rt->qmn(i,n-1);
		if(mn<0)num=0;
		else num=min(num,mn/(2*d[i]));
		
		//printf("d=%d cur=%d, num=%d\n",d[i],cur,num);
		ans-=num;
		rt->up(i,n-1,-num*d[i]*2);
		rt->set(i);
		//for(int i=0;i<n;++i)printf("%d ",rt->qry(i));
		//printf("\n");
	}
	pf("%lld\n",ans);
	fprintf(stderr,"%lld\n",ans);
}

Compilation message

tortoise.cpp:113:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  113 | main(){
      | ^~~~
tortoise.cpp: In function 'int main()':
tortoise.cpp:158:39: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  158 |   int num=min(a[i],cur/(2*d[i])+(pv[i]==play.size()-1||i<mx[pv[i]+1]));
      |                                  ~~~~~^~~~~~~~~~~~~~~
tortoise.cpp:114:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |  sf("%lld",&n);
      |    ^
tortoise.cpp:117:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |   sf("%lld",&a[i]);
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 3 ms 4152 KB Output is correct
3 Correct 3 ms 4148 KB Output is correct
4 Correct 3 ms 4160 KB Output is correct
5 Correct 3 ms 4180 KB Output is correct
6 Correct 2 ms 4180 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
10 Correct 3 ms 4180 KB Output is correct
11 Correct 3 ms 4180 KB Output is correct
12 Correct 2 ms 4180 KB Output is correct
13 Correct 2 ms 4156 KB Output is correct
14 Correct 3 ms 4180 KB Output is correct
15 Correct 3 ms 4152 KB Output is correct
16 Correct 2 ms 4180 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 2 ms 4180 KB Output is correct
19 Correct 2 ms 4148 KB Output is correct
20 Correct 2 ms 4148 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 3 ms 4180 KB Output is correct
23 Correct 3 ms 4152 KB Output is correct
24 Correct 3 ms 4180 KB Output is correct
25 Correct 2 ms 4180 KB Output is correct
26 Correct 3 ms 4144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 3 ms 4152 KB Output is correct
3 Correct 3 ms 4148 KB Output is correct
4 Correct 3 ms 4160 KB Output is correct
5 Correct 3 ms 4180 KB Output is correct
6 Correct 2 ms 4180 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
10 Correct 3 ms 4180 KB Output is correct
11 Correct 3 ms 4180 KB Output is correct
12 Correct 2 ms 4180 KB Output is correct
13 Correct 2 ms 4156 KB Output is correct
14 Correct 3 ms 4180 KB Output is correct
15 Correct 3 ms 4152 KB Output is correct
16 Correct 2 ms 4180 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 2 ms 4180 KB Output is correct
19 Correct 2 ms 4148 KB Output is correct
20 Correct 2 ms 4148 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 3 ms 4180 KB Output is correct
23 Correct 3 ms 4152 KB Output is correct
24 Correct 3 ms 4180 KB Output is correct
25 Correct 2 ms 4180 KB Output is correct
26 Correct 3 ms 4144 KB Output is correct
27 Correct 3 ms 4308 KB Output is correct
28 Correct 3 ms 4276 KB Output is correct
29 Correct 3 ms 4280 KB Output is correct
30 Correct 4 ms 4308 KB Output is correct
31 Correct 3 ms 4280 KB Output is correct
32 Correct 3 ms 4280 KB Output is correct
33 Correct 3 ms 4308 KB Output is correct
34 Correct 3 ms 4308 KB Output is correct
35 Correct 3 ms 4328 KB Output is correct
36 Correct 3 ms 4308 KB Output is correct
37 Correct 3 ms 4308 KB Output is correct
38 Correct 3 ms 4276 KB Output is correct
39 Correct 3 ms 4308 KB Output is correct
40 Correct 3 ms 4280 KB Output is correct
41 Correct 3 ms 4308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 3 ms 4152 KB Output is correct
3 Correct 3 ms 4148 KB Output is correct
4 Correct 3 ms 4160 KB Output is correct
5 Correct 3 ms 4180 KB Output is correct
6 Correct 2 ms 4180 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
10 Correct 3 ms 4180 KB Output is correct
11 Correct 3 ms 4180 KB Output is correct
12 Correct 2 ms 4180 KB Output is correct
13 Correct 2 ms 4156 KB Output is correct
14 Correct 3 ms 4180 KB Output is correct
15 Correct 3 ms 4152 KB Output is correct
16 Correct 2 ms 4180 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 2 ms 4180 KB Output is correct
19 Correct 2 ms 4148 KB Output is correct
20 Correct 2 ms 4148 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 3 ms 4180 KB Output is correct
23 Correct 3 ms 4152 KB Output is correct
24 Correct 3 ms 4180 KB Output is correct
25 Correct 2 ms 4180 KB Output is correct
26 Correct 3 ms 4144 KB Output is correct
27 Correct 3 ms 4308 KB Output is correct
28 Correct 3 ms 4276 KB Output is correct
29 Correct 3 ms 4280 KB Output is correct
30 Correct 4 ms 4308 KB Output is correct
31 Correct 3 ms 4280 KB Output is correct
32 Correct 3 ms 4280 KB Output is correct
33 Correct 3 ms 4308 KB Output is correct
34 Correct 3 ms 4308 KB Output is correct
35 Correct 3 ms 4328 KB Output is correct
36 Correct 3 ms 4308 KB Output is correct
37 Correct 3 ms 4308 KB Output is correct
38 Correct 3 ms 4276 KB Output is correct
39 Correct 3 ms 4308 KB Output is correct
40 Correct 3 ms 4280 KB Output is correct
41 Correct 3 ms 4308 KB Output is correct
42 Correct 3 ms 4280 KB Output is correct
43 Correct 2 ms 4308 KB Output is correct
44 Correct 2 ms 4308 KB Output is correct
45 Correct 2 ms 4308 KB Output is correct
46 Correct 2 ms 4284 KB Output is correct
47 Correct 3 ms 4308 KB Output is correct
48 Correct 3 ms 4308 KB Output is correct
49 Correct 2 ms 4280 KB Output is correct
50 Correct 3 ms 4284 KB Output is correct
51 Correct 3 ms 4308 KB Output is correct
52 Correct 2 ms 4308 KB Output is correct
53 Correct 3 ms 4308 KB Output is correct
54 Correct 3 ms 4308 KB Output is correct
55 Correct 3 ms 4284 KB Output is correct
56 Correct 2 ms 4308 KB Output is correct
57 Incorrect 4 ms 4308 KB Output isn't correct
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 3 ms 4152 KB Output is correct
3 Correct 3 ms 4148 KB Output is correct
4 Correct 3 ms 4160 KB Output is correct
5 Correct 3 ms 4180 KB Output is correct
6 Correct 2 ms 4180 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
10 Correct 3 ms 4180 KB Output is correct
11 Correct 3 ms 4180 KB Output is correct
12 Correct 2 ms 4180 KB Output is correct
13 Correct 2 ms 4156 KB Output is correct
14 Correct 3 ms 4180 KB Output is correct
15 Correct 3 ms 4152 KB Output is correct
16 Correct 2 ms 4180 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 2 ms 4180 KB Output is correct
19 Correct 2 ms 4148 KB Output is correct
20 Correct 2 ms 4148 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 3 ms 4180 KB Output is correct
23 Correct 3 ms 4152 KB Output is correct
24 Correct 3 ms 4180 KB Output is correct
25 Correct 2 ms 4180 KB Output is correct
26 Correct 3 ms 4144 KB Output is correct
27 Correct 3 ms 4308 KB Output is correct
28 Correct 3 ms 4276 KB Output is correct
29 Correct 3 ms 4280 KB Output is correct
30 Correct 4 ms 4308 KB Output is correct
31 Correct 3 ms 4280 KB Output is correct
32 Correct 3 ms 4280 KB Output is correct
33 Correct 3 ms 4308 KB Output is correct
34 Correct 3 ms 4308 KB Output is correct
35 Correct 3 ms 4328 KB Output is correct
36 Correct 3 ms 4308 KB Output is correct
37 Correct 3 ms 4308 KB Output is correct
38 Correct 3 ms 4276 KB Output is correct
39 Correct 3 ms 4308 KB Output is correct
40 Correct 3 ms 4280 KB Output is correct
41 Correct 3 ms 4308 KB Output is correct
42 Correct 3 ms 4280 KB Output is correct
43 Correct 2 ms 4308 KB Output is correct
44 Correct 2 ms 4308 KB Output is correct
45 Correct 2 ms 4308 KB Output is correct
46 Correct 2 ms 4284 KB Output is correct
47 Correct 3 ms 4308 KB Output is correct
48 Correct 3 ms 4308 KB Output is correct
49 Correct 2 ms 4280 KB Output is correct
50 Correct 3 ms 4284 KB Output is correct
51 Correct 3 ms 4308 KB Output is correct
52 Correct 2 ms 4308 KB Output is correct
53 Correct 3 ms 4308 KB Output is correct
54 Correct 3 ms 4308 KB Output is correct
55 Correct 3 ms 4284 KB Output is correct
56 Correct 2 ms 4308 KB Output is correct
57 Incorrect 4 ms 4308 KB Output isn't correct
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 3 ms 4152 KB Output is correct
3 Correct 3 ms 4148 KB Output is correct
4 Correct 3 ms 4160 KB Output is correct
5 Correct 3 ms 4180 KB Output is correct
6 Correct 2 ms 4180 KB Output is correct
7 Correct 3 ms 4180 KB Output is correct
8 Correct 2 ms 4180 KB Output is correct
9 Correct 3 ms 4180 KB Output is correct
10 Correct 3 ms 4180 KB Output is correct
11 Correct 3 ms 4180 KB Output is correct
12 Correct 2 ms 4180 KB Output is correct
13 Correct 2 ms 4156 KB Output is correct
14 Correct 3 ms 4180 KB Output is correct
15 Correct 3 ms 4152 KB Output is correct
16 Correct 2 ms 4180 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 2 ms 4180 KB Output is correct
19 Correct 2 ms 4148 KB Output is correct
20 Correct 2 ms 4148 KB Output is correct
21 Correct 3 ms 4180 KB Output is correct
22 Correct 3 ms 4180 KB Output is correct
23 Correct 3 ms 4152 KB Output is correct
24 Correct 3 ms 4180 KB Output is correct
25 Correct 2 ms 4180 KB Output is correct
26 Correct 3 ms 4144 KB Output is correct
27 Correct 3 ms 4308 KB Output is correct
28 Correct 3 ms 4276 KB Output is correct
29 Correct 3 ms 4280 KB Output is correct
30 Correct 4 ms 4308 KB Output is correct
31 Correct 3 ms 4280 KB Output is correct
32 Correct 3 ms 4280 KB Output is correct
33 Correct 3 ms 4308 KB Output is correct
34 Correct 3 ms 4308 KB Output is correct
35 Correct 3 ms 4328 KB Output is correct
36 Correct 3 ms 4308 KB Output is correct
37 Correct 3 ms 4308 KB Output is correct
38 Correct 3 ms 4276 KB Output is correct
39 Correct 3 ms 4308 KB Output is correct
40 Correct 3 ms 4280 KB Output is correct
41 Correct 3 ms 4308 KB Output is correct
42 Correct 3 ms 4280 KB Output is correct
43 Correct 2 ms 4308 KB Output is correct
44 Correct 2 ms 4308 KB Output is correct
45 Correct 2 ms 4308 KB Output is correct
46 Correct 2 ms 4284 KB Output is correct
47 Correct 3 ms 4308 KB Output is correct
48 Correct 3 ms 4308 KB Output is correct
49 Correct 2 ms 4280 KB Output is correct
50 Correct 3 ms 4284 KB Output is correct
51 Correct 3 ms 4308 KB Output is correct
52 Correct 2 ms 4308 KB Output is correct
53 Correct 3 ms 4308 KB Output is correct
54 Correct 3 ms 4308 KB Output is correct
55 Correct 3 ms 4284 KB Output is correct
56 Correct 2 ms 4308 KB Output is correct
57 Incorrect 4 ms 4308 KB Output isn't correct
58 Halted 0 ms 0 KB -