Submission #743799

# Submission time Handle Problem Language Result Execution time Memory
743799 2023-05-18T03:09:09 Z jamezzz Tortoise (CEOI21_tortoise) C++17
18 / 100
2 ms 2304 KB
#include <bits/stdc++.h>
using namespace std;

#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;

int main(){
	sf("%d",&n);
	rt=new node(0,n-1);
	for(int i=0;i<n;++i){
		sf("%d",&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]])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("take %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]));
		
		if(i+1<n){
			int mn=rt->qmn(i+1,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);
}

Compilation message

tortoise.cpp: In function 'int main()':
tortoise.cpp:156:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  156 |   int num=min(a[i],cur/(2*d[i])+(pv[i]==play.size()-1||i<mx[pv[i]+1]));
      |                                  ~~~~~^~~~~~~~~~~~~~~
tortoise.cpp:112:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  112 |  sf("%d",&n);
      |    ^
tortoise.cpp:115:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |   sf("%d",&a[i]);
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 2 ms 2236 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 1 ms 2260 KB Output is correct
11 Correct 1 ms 2260 KB Output is correct
12 Correct 1 ms 2260 KB Output is correct
13 Correct 1 ms 2260 KB Output is correct
14 Correct 2 ms 2196 KB Output is correct
15 Correct 1 ms 2236 KB Output is correct
16 Correct 1 ms 2260 KB Output is correct
17 Correct 1 ms 2260 KB Output is correct
18 Correct 1 ms 2260 KB Output is correct
19 Correct 1 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
21 Correct 1 ms 2260 KB Output is correct
22 Correct 2 ms 2236 KB Output is correct
23 Correct 2 ms 2304 KB Output is correct
24 Correct 1 ms 2260 KB Output is correct
25 Correct 1 ms 2260 KB Output is correct
26 Correct 1 ms 2232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 2 ms 2236 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 1 ms 2260 KB Output is correct
11 Correct 1 ms 2260 KB Output is correct
12 Correct 1 ms 2260 KB Output is correct
13 Correct 1 ms 2260 KB Output is correct
14 Correct 2 ms 2196 KB Output is correct
15 Correct 1 ms 2236 KB Output is correct
16 Correct 1 ms 2260 KB Output is correct
17 Correct 1 ms 2260 KB Output is correct
18 Correct 1 ms 2260 KB Output is correct
19 Correct 1 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
21 Correct 1 ms 2260 KB Output is correct
22 Correct 2 ms 2236 KB Output is correct
23 Correct 2 ms 2304 KB Output is correct
24 Correct 1 ms 2260 KB Output is correct
25 Correct 1 ms 2260 KB Output is correct
26 Correct 1 ms 2232 KB Output is correct
27 Correct 2 ms 2232 KB Output is correct
28 Correct 2 ms 2260 KB Output is correct
29 Correct 2 ms 2260 KB Output is correct
30 Correct 2 ms 2260 KB Output is correct
31 Correct 1 ms 2260 KB Output is correct
32 Correct 2 ms 2236 KB Output is correct
33 Correct 2 ms 2260 KB Output is correct
34 Correct 1 ms 2260 KB Output is correct
35 Correct 2 ms 2260 KB Output is correct
36 Correct 1 ms 2260 KB Output is correct
37 Correct 2 ms 2260 KB Output is correct
38 Correct 1 ms 2260 KB Output is correct
39 Correct 1 ms 2260 KB Output is correct
40 Correct 2 ms 2232 KB Output is correct
41 Correct 2 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 2 ms 2236 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 1 ms 2260 KB Output is correct
11 Correct 1 ms 2260 KB Output is correct
12 Correct 1 ms 2260 KB Output is correct
13 Correct 1 ms 2260 KB Output is correct
14 Correct 2 ms 2196 KB Output is correct
15 Correct 1 ms 2236 KB Output is correct
16 Correct 1 ms 2260 KB Output is correct
17 Correct 1 ms 2260 KB Output is correct
18 Correct 1 ms 2260 KB Output is correct
19 Correct 1 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
21 Correct 1 ms 2260 KB Output is correct
22 Correct 2 ms 2236 KB Output is correct
23 Correct 2 ms 2304 KB Output is correct
24 Correct 1 ms 2260 KB Output is correct
25 Correct 1 ms 2260 KB Output is correct
26 Correct 1 ms 2232 KB Output is correct
27 Correct 2 ms 2232 KB Output is correct
28 Correct 2 ms 2260 KB Output is correct
29 Correct 2 ms 2260 KB Output is correct
30 Correct 2 ms 2260 KB Output is correct
31 Correct 1 ms 2260 KB Output is correct
32 Correct 2 ms 2236 KB Output is correct
33 Correct 2 ms 2260 KB Output is correct
34 Correct 1 ms 2260 KB Output is correct
35 Correct 2 ms 2260 KB Output is correct
36 Correct 1 ms 2260 KB Output is correct
37 Correct 2 ms 2260 KB Output is correct
38 Correct 1 ms 2260 KB Output is correct
39 Correct 1 ms 2260 KB Output is correct
40 Correct 2 ms 2232 KB Output is correct
41 Correct 2 ms 2260 KB Output is correct
42 Correct 2 ms 2260 KB Output is correct
43 Correct 2 ms 2224 KB Output is correct
44 Correct 2 ms 2260 KB Output is correct
45 Correct 2 ms 2260 KB Output is correct
46 Correct 2 ms 2260 KB Output is correct
47 Correct 2 ms 2260 KB Output is correct
48 Correct 1 ms 2260 KB Output is correct
49 Correct 2 ms 2260 KB Output is correct
50 Correct 2 ms 2260 KB Output is correct
51 Correct 2 ms 2232 KB Output is correct
52 Correct 1 ms 2260 KB Output is correct
53 Correct 1 ms 2260 KB Output is correct
54 Correct 2 ms 2260 KB Output is correct
55 Correct 2 ms 2260 KB Output is correct
56 Correct 2 ms 2236 KB Output is correct
57 Correct 2 ms 2260 KB Output is correct
58 Correct 1 ms 2260 KB Output is correct
59 Incorrect 2 ms 2232 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 2 ms 2236 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 1 ms 2260 KB Output is correct
11 Correct 1 ms 2260 KB Output is correct
12 Correct 1 ms 2260 KB Output is correct
13 Correct 1 ms 2260 KB Output is correct
14 Correct 2 ms 2196 KB Output is correct
15 Correct 1 ms 2236 KB Output is correct
16 Correct 1 ms 2260 KB Output is correct
17 Correct 1 ms 2260 KB Output is correct
18 Correct 1 ms 2260 KB Output is correct
19 Correct 1 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
21 Correct 1 ms 2260 KB Output is correct
22 Correct 2 ms 2236 KB Output is correct
23 Correct 2 ms 2304 KB Output is correct
24 Correct 1 ms 2260 KB Output is correct
25 Correct 1 ms 2260 KB Output is correct
26 Correct 1 ms 2232 KB Output is correct
27 Correct 2 ms 2232 KB Output is correct
28 Correct 2 ms 2260 KB Output is correct
29 Correct 2 ms 2260 KB Output is correct
30 Correct 2 ms 2260 KB Output is correct
31 Correct 1 ms 2260 KB Output is correct
32 Correct 2 ms 2236 KB Output is correct
33 Correct 2 ms 2260 KB Output is correct
34 Correct 1 ms 2260 KB Output is correct
35 Correct 2 ms 2260 KB Output is correct
36 Correct 1 ms 2260 KB Output is correct
37 Correct 2 ms 2260 KB Output is correct
38 Correct 1 ms 2260 KB Output is correct
39 Correct 1 ms 2260 KB Output is correct
40 Correct 2 ms 2232 KB Output is correct
41 Correct 2 ms 2260 KB Output is correct
42 Correct 2 ms 2260 KB Output is correct
43 Correct 2 ms 2224 KB Output is correct
44 Correct 2 ms 2260 KB Output is correct
45 Correct 2 ms 2260 KB Output is correct
46 Correct 2 ms 2260 KB Output is correct
47 Correct 2 ms 2260 KB Output is correct
48 Correct 1 ms 2260 KB Output is correct
49 Correct 2 ms 2260 KB Output is correct
50 Correct 2 ms 2260 KB Output is correct
51 Correct 2 ms 2232 KB Output is correct
52 Correct 1 ms 2260 KB Output is correct
53 Correct 1 ms 2260 KB Output is correct
54 Correct 2 ms 2260 KB Output is correct
55 Correct 2 ms 2260 KB Output is correct
56 Correct 2 ms 2236 KB Output is correct
57 Correct 2 ms 2260 KB Output is correct
58 Correct 1 ms 2260 KB Output is correct
59 Incorrect 2 ms 2232 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 2 ms 2236 KB Output is correct
3 Correct 1 ms 2260 KB Output is correct
4 Correct 2 ms 2260 KB Output is correct
5 Correct 1 ms 2260 KB Output is correct
6 Correct 2 ms 2260 KB Output is correct
7 Correct 1 ms 2260 KB Output is correct
8 Correct 1 ms 2260 KB Output is correct
9 Correct 1 ms 2260 KB Output is correct
10 Correct 1 ms 2260 KB Output is correct
11 Correct 1 ms 2260 KB Output is correct
12 Correct 1 ms 2260 KB Output is correct
13 Correct 1 ms 2260 KB Output is correct
14 Correct 2 ms 2196 KB Output is correct
15 Correct 1 ms 2236 KB Output is correct
16 Correct 1 ms 2260 KB Output is correct
17 Correct 1 ms 2260 KB Output is correct
18 Correct 1 ms 2260 KB Output is correct
19 Correct 1 ms 2260 KB Output is correct
20 Correct 2 ms 2260 KB Output is correct
21 Correct 1 ms 2260 KB Output is correct
22 Correct 2 ms 2236 KB Output is correct
23 Correct 2 ms 2304 KB Output is correct
24 Correct 1 ms 2260 KB Output is correct
25 Correct 1 ms 2260 KB Output is correct
26 Correct 1 ms 2232 KB Output is correct
27 Correct 2 ms 2232 KB Output is correct
28 Correct 2 ms 2260 KB Output is correct
29 Correct 2 ms 2260 KB Output is correct
30 Correct 2 ms 2260 KB Output is correct
31 Correct 1 ms 2260 KB Output is correct
32 Correct 2 ms 2236 KB Output is correct
33 Correct 2 ms 2260 KB Output is correct
34 Correct 1 ms 2260 KB Output is correct
35 Correct 2 ms 2260 KB Output is correct
36 Correct 1 ms 2260 KB Output is correct
37 Correct 2 ms 2260 KB Output is correct
38 Correct 1 ms 2260 KB Output is correct
39 Correct 1 ms 2260 KB Output is correct
40 Correct 2 ms 2232 KB Output is correct
41 Correct 2 ms 2260 KB Output is correct
42 Correct 2 ms 2260 KB Output is correct
43 Correct 2 ms 2224 KB Output is correct
44 Correct 2 ms 2260 KB Output is correct
45 Correct 2 ms 2260 KB Output is correct
46 Correct 2 ms 2260 KB Output is correct
47 Correct 2 ms 2260 KB Output is correct
48 Correct 1 ms 2260 KB Output is correct
49 Correct 2 ms 2260 KB Output is correct
50 Correct 2 ms 2260 KB Output is correct
51 Correct 2 ms 2232 KB Output is correct
52 Correct 1 ms 2260 KB Output is correct
53 Correct 1 ms 2260 KB Output is correct
54 Correct 2 ms 2260 KB Output is correct
55 Correct 2 ms 2260 KB Output is correct
56 Correct 2 ms 2236 KB Output is correct
57 Correct 2 ms 2260 KB Output is correct
58 Correct 1 ms 2260 KB Output is correct
59 Incorrect 2 ms 2232 KB Output isn't correct
60 Halted 0 ms 0 KB -