Submission #387011

# Submission time Handle Problem Language Result Execution time Memory
387011 2021-04-07T19:33:31 Z AmineWeslati Food Court (JOI21_foodcourt) C++14
68 / 100
1000 ms 33672 KB
//Never stop trying
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
typedef string str;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

const int MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const int MX = 250000 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

template<class T> using V = vector<T>;
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
//constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
ll random(ll a, ll b){
    return a + rng() % (b - a + 1);
}
#ifndef LOCAL  
#define cerr if(false) cerr
#endif
#define dbg(x) cerr << #x << " : " << x << endl; 
#define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);
#endif
}
/////////////////////////ONLY CLEAN CODES ALLOWED/////////////////////////

int N,M,Q,ans[MX],C[MX],K[MX]; 
ll B[MX]; 
vpi q[MX]; 
vi q3[MX];

V<ll> ft(MX,0);
void upd2(int i, int v){
	i++;
	for(;i<MX; i+=i&-i) ft[i]+=v;
}
ll get(int i){
	i++;
	ll ans=0;
	for(;i;i-=i&-i) ans+=ft[i];
	return ans; 
}

ll summ(int l, int r){
	return get(r)-get(l-1);
}

const int S=600;
V<ll> a(MX,0),sum(MX,0),mnp(MX,INF);

void upd(int idx, int v){
	a[idx]+=v;
	idx/=S;
	sum[idx]=0; mnp[idx]=INF;
	FOR(i,idx*S,min((idx+1)*S,Q)){
		sum[idx]+=a[i];
		ckmin(mnp[idx],sum[idx]);
	}
}

int c; 
int solve(int idx){
	ll cur=0;
	FOR(b,0,idx/S){
		if(-mnp[b]>cur)
			cur+=-mnp[b]-cur;
		cur+=sum[b];
	}

	FOR(i,(idx/S)*S,idx+1){
		cur+=a[i];
		if(cur<0) cur=0;
	}

	if(cur<B[idx]) return 0;
	if(M==1) return c;

	ll x=cur-B[idx]+1;
	int i,l=0,r=idx;
	while(l<=r){
		int m=(l+r)/2;
		if(summ(m,idx)>=x){
			i=m;
			l=m+1;
		}
		else r=m-1;
	}
	return C[i];
}

int main() {
    boost; IO();
    memset(C,-1,sizeof(C));
    memset(ans,-1,sizeof(C));

    cin>>N>>M>>Q;
    FOR(i,0,Q){
    	int t; cin>>t;
    	if(t==1){
    		int l,r; cin>>l>>r>>C[i]>>K[i]; l--; r--;
    		q[l].eb(i,1);
    		q[r+1].eb(i,-1);
    		c=C[i];
    	}
    	else if(t==2){
    		int l,r; cin>>l>>r>>K[i]; l--; r--;
    		q[l].eb(i,1);
    		q[r+1].eb(i,-1);
    	}
    	else{
    		int idx; cin>>idx>>B[i]; idx--;
    		q3[idx].pb(i);
    	}
    }


    FOR(i,0,N){
    	for(auto it: q[i]){
    		int idx=it.fi,t=it.se;
    		if(C[idx]!=-1) upd(idx,K[idx]*t),upd2(idx,K[idx]*t);
    		else upd(idx,-K[idx]*t);
    	}
    	for(int idx: q3[i]){
    		ans[idx]=solve(idx);
    	}
    }
    FOR(i,0,Q) if(ans[i]!=-1) cout << ans[i] << endl;

    return 0;
}
//Change your approach 

Compilation message

foodcourt.cpp: In function 'int solve(int)':
foodcourt.cpp:116:12: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
  116 |  return C[i];
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 19 ms 21996 KB Output is correct
2 Correct 22 ms 21996 KB Output is correct
3 Correct 22 ms 21996 KB Output is correct
4 Correct 22 ms 21996 KB Output is correct
5 Correct 18 ms 21996 KB Output is correct
6 Correct 18 ms 21996 KB Output is correct
7 Correct 24 ms 22144 KB Output is correct
8 Correct 26 ms 21996 KB Output is correct
9 Correct 26 ms 21996 KB Output is correct
10 Correct 26 ms 21996 KB Output is correct
11 Correct 23 ms 21996 KB Output is correct
12 Correct 24 ms 21996 KB Output is correct
13 Correct 18 ms 21996 KB Output is correct
14 Correct 20 ms 22144 KB Output is correct
15 Correct 22 ms 21996 KB Output is correct
16 Correct 23 ms 21996 KB Output is correct
17 Correct 24 ms 21996 KB Output is correct
18 Correct 23 ms 22036 KB Output is correct
19 Correct 22 ms 21996 KB Output is correct
20 Correct 27 ms 21996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 21996 KB Output is correct
2 Correct 22 ms 21996 KB Output is correct
3 Correct 22 ms 21996 KB Output is correct
4 Correct 22 ms 21996 KB Output is correct
5 Correct 18 ms 21996 KB Output is correct
6 Correct 18 ms 21996 KB Output is correct
7 Correct 24 ms 22144 KB Output is correct
8 Correct 26 ms 21996 KB Output is correct
9 Correct 26 ms 21996 KB Output is correct
10 Correct 26 ms 21996 KB Output is correct
11 Correct 23 ms 21996 KB Output is correct
12 Correct 24 ms 21996 KB Output is correct
13 Correct 18 ms 21996 KB Output is correct
14 Correct 20 ms 22144 KB Output is correct
15 Correct 22 ms 21996 KB Output is correct
16 Correct 23 ms 21996 KB Output is correct
17 Correct 24 ms 21996 KB Output is correct
18 Correct 23 ms 22036 KB Output is correct
19 Correct 22 ms 21996 KB Output is correct
20 Correct 27 ms 21996 KB Output is correct
21 Correct 23 ms 21996 KB Output is correct
22 Correct 23 ms 21996 KB Output is correct
23 Correct 22 ms 21996 KB Output is correct
24 Correct 22 ms 21996 KB Output is correct
25 Correct 20 ms 21996 KB Output is correct
26 Correct 19 ms 21996 KB Output is correct
27 Correct 23 ms 21996 KB Output is correct
28 Correct 26 ms 21996 KB Output is correct
29 Correct 22 ms 21996 KB Output is correct
30 Correct 24 ms 21996 KB Output is correct
31 Correct 24 ms 21996 KB Output is correct
32 Correct 24 ms 21996 KB Output is correct
33 Correct 19 ms 21996 KB Output is correct
34 Correct 21 ms 21996 KB Output is correct
35 Correct 22 ms 22028 KB Output is correct
36 Correct 23 ms 21996 KB Output is correct
37 Correct 26 ms 21996 KB Output is correct
38 Correct 22 ms 21996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 309 ms 24944 KB Output is correct
2 Correct 333 ms 24988 KB Output is correct
3 Correct 306 ms 24972 KB Output is correct
4 Correct 315 ms 25068 KB Output is correct
5 Correct 324 ms 24940 KB Output is correct
6 Correct 309 ms 24900 KB Output is correct
7 Correct 173 ms 23528 KB Output is correct
8 Correct 180 ms 23620 KB Output is correct
9 Correct 378 ms 24940 KB Output is correct
10 Correct 380 ms 24940 KB Output is correct
11 Correct 393 ms 24940 KB Output is correct
12 Correct 364 ms 24940 KB Output is correct
13 Correct 234 ms 24556 KB Output is correct
14 Correct 270 ms 25068 KB Output is correct
15 Correct 287 ms 24732 KB Output is correct
16 Correct 273 ms 24940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 966 ms 32696 KB Output is correct
2 Correct 755 ms 30572 KB Output is correct
3 Execution timed out 1028 ms 33672 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 21996 KB Output is correct
2 Correct 22 ms 21996 KB Output is correct
3 Correct 22 ms 21996 KB Output is correct
4 Correct 22 ms 21996 KB Output is correct
5 Correct 18 ms 21996 KB Output is correct
6 Correct 18 ms 21996 KB Output is correct
7 Correct 24 ms 22144 KB Output is correct
8 Correct 26 ms 21996 KB Output is correct
9 Correct 26 ms 21996 KB Output is correct
10 Correct 26 ms 21996 KB Output is correct
11 Correct 23 ms 21996 KB Output is correct
12 Correct 24 ms 21996 KB Output is correct
13 Correct 18 ms 21996 KB Output is correct
14 Correct 20 ms 22144 KB Output is correct
15 Correct 22 ms 21996 KB Output is correct
16 Correct 23 ms 21996 KB Output is correct
17 Correct 24 ms 21996 KB Output is correct
18 Correct 23 ms 22036 KB Output is correct
19 Correct 22 ms 21996 KB Output is correct
20 Correct 27 ms 21996 KB Output is correct
21 Correct 309 ms 24944 KB Output is correct
22 Correct 333 ms 24988 KB Output is correct
23 Correct 306 ms 24972 KB Output is correct
24 Correct 315 ms 25068 KB Output is correct
25 Correct 324 ms 24940 KB Output is correct
26 Correct 309 ms 24900 KB Output is correct
27 Correct 173 ms 23528 KB Output is correct
28 Correct 180 ms 23620 KB Output is correct
29 Correct 378 ms 24940 KB Output is correct
30 Correct 380 ms 24940 KB Output is correct
31 Correct 393 ms 24940 KB Output is correct
32 Correct 364 ms 24940 KB Output is correct
33 Correct 234 ms 24556 KB Output is correct
34 Correct 270 ms 25068 KB Output is correct
35 Correct 287 ms 24732 KB Output is correct
36 Correct 273 ms 24940 KB Output is correct
37 Correct 235 ms 24684 KB Output is correct
38 Correct 212 ms 24428 KB Output is correct
39 Correct 132 ms 23432 KB Output is correct
40 Correct 178 ms 23692 KB Output is correct
41 Correct 374 ms 24940 KB Output is correct
42 Correct 345 ms 25004 KB Output is correct
43 Correct 277 ms 24940 KB Output is correct
44 Correct 344 ms 24960 KB Output is correct
45 Correct 315 ms 25032 KB Output is correct
46 Correct 299 ms 24980 KB Output is correct
47 Correct 152 ms 24020 KB Output is correct
48 Correct 238 ms 24512 KB Output is correct
49 Correct 199 ms 24044 KB Output is correct
50 Correct 244 ms 24684 KB Output is correct
51 Correct 291 ms 25024 KB Output is correct
52 Correct 297 ms 25068 KB Output is correct
53 Correct 219 ms 24348 KB Output is correct
54 Correct 277 ms 24940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 198 ms 24684 KB Output is correct
2 Correct 213 ms 24940 KB Output is correct
3 Correct 219 ms 25068 KB Output is correct
4 Correct 164 ms 24116 KB Output is correct
5 Correct 196 ms 24684 KB Output is correct
6 Correct 232 ms 25068 KB Output is correct
7 Correct 115 ms 23388 KB Output is correct
8 Correct 117 ms 23404 KB Output is correct
9 Correct 144 ms 24168 KB Output is correct
10 Correct 145 ms 23660 KB Output is correct
11 Correct 202 ms 24300 KB Output is correct
12 Correct 207 ms 24428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 21996 KB Output is correct
2 Correct 22 ms 21996 KB Output is correct
3 Correct 22 ms 21996 KB Output is correct
4 Correct 22 ms 21996 KB Output is correct
5 Correct 18 ms 21996 KB Output is correct
6 Correct 18 ms 21996 KB Output is correct
7 Correct 24 ms 22144 KB Output is correct
8 Correct 26 ms 21996 KB Output is correct
9 Correct 26 ms 21996 KB Output is correct
10 Correct 26 ms 21996 KB Output is correct
11 Correct 23 ms 21996 KB Output is correct
12 Correct 24 ms 21996 KB Output is correct
13 Correct 18 ms 21996 KB Output is correct
14 Correct 20 ms 22144 KB Output is correct
15 Correct 22 ms 21996 KB Output is correct
16 Correct 23 ms 21996 KB Output is correct
17 Correct 24 ms 21996 KB Output is correct
18 Correct 23 ms 22036 KB Output is correct
19 Correct 22 ms 21996 KB Output is correct
20 Correct 27 ms 21996 KB Output is correct
21 Correct 23 ms 21996 KB Output is correct
22 Correct 23 ms 21996 KB Output is correct
23 Correct 22 ms 21996 KB Output is correct
24 Correct 22 ms 21996 KB Output is correct
25 Correct 20 ms 21996 KB Output is correct
26 Correct 19 ms 21996 KB Output is correct
27 Correct 23 ms 21996 KB Output is correct
28 Correct 26 ms 21996 KB Output is correct
29 Correct 22 ms 21996 KB Output is correct
30 Correct 24 ms 21996 KB Output is correct
31 Correct 24 ms 21996 KB Output is correct
32 Correct 24 ms 21996 KB Output is correct
33 Correct 19 ms 21996 KB Output is correct
34 Correct 21 ms 21996 KB Output is correct
35 Correct 22 ms 22028 KB Output is correct
36 Correct 23 ms 21996 KB Output is correct
37 Correct 26 ms 21996 KB Output is correct
38 Correct 22 ms 21996 KB Output is correct
39 Correct 309 ms 24944 KB Output is correct
40 Correct 333 ms 24988 KB Output is correct
41 Correct 306 ms 24972 KB Output is correct
42 Correct 315 ms 25068 KB Output is correct
43 Correct 324 ms 24940 KB Output is correct
44 Correct 309 ms 24900 KB Output is correct
45 Correct 173 ms 23528 KB Output is correct
46 Correct 180 ms 23620 KB Output is correct
47 Correct 378 ms 24940 KB Output is correct
48 Correct 380 ms 24940 KB Output is correct
49 Correct 393 ms 24940 KB Output is correct
50 Correct 364 ms 24940 KB Output is correct
51 Correct 234 ms 24556 KB Output is correct
52 Correct 270 ms 25068 KB Output is correct
53 Correct 287 ms 24732 KB Output is correct
54 Correct 273 ms 24940 KB Output is correct
55 Correct 235 ms 24684 KB Output is correct
56 Correct 212 ms 24428 KB Output is correct
57 Correct 132 ms 23432 KB Output is correct
58 Correct 178 ms 23692 KB Output is correct
59 Correct 374 ms 24940 KB Output is correct
60 Correct 345 ms 25004 KB Output is correct
61 Correct 277 ms 24940 KB Output is correct
62 Correct 344 ms 24960 KB Output is correct
63 Correct 315 ms 25032 KB Output is correct
64 Correct 299 ms 24980 KB Output is correct
65 Correct 152 ms 24020 KB Output is correct
66 Correct 238 ms 24512 KB Output is correct
67 Correct 199 ms 24044 KB Output is correct
68 Correct 244 ms 24684 KB Output is correct
69 Correct 291 ms 25024 KB Output is correct
70 Correct 297 ms 25068 KB Output is correct
71 Correct 219 ms 24348 KB Output is correct
72 Correct 277 ms 24940 KB Output is correct
73 Correct 198 ms 24684 KB Output is correct
74 Correct 213 ms 24940 KB Output is correct
75 Correct 219 ms 25068 KB Output is correct
76 Correct 164 ms 24116 KB Output is correct
77 Correct 196 ms 24684 KB Output is correct
78 Correct 232 ms 25068 KB Output is correct
79 Correct 115 ms 23388 KB Output is correct
80 Correct 117 ms 23404 KB Output is correct
81 Correct 144 ms 24168 KB Output is correct
82 Correct 145 ms 23660 KB Output is correct
83 Correct 202 ms 24300 KB Output is correct
84 Correct 207 ms 24428 KB Output is correct
85 Correct 250 ms 24616 KB Output is correct
86 Correct 276 ms 25068 KB Output is correct
87 Correct 242 ms 24628 KB Output is correct
88 Correct 278 ms 24972 KB Output is correct
89 Correct 273 ms 24172 KB Output is correct
90 Correct 372 ms 25068 KB Output is correct
91 Correct 276 ms 24300 KB Output is correct
92 Correct 228 ms 24172 KB Output is correct
93 Correct 293 ms 25068 KB Output is correct
94 Correct 340 ms 24956 KB Output is correct
95 Correct 330 ms 24812 KB Output is correct
96 Correct 328 ms 25068 KB Output is correct
97 Correct 285 ms 24940 KB Output is correct
98 Correct 237 ms 24428 KB Output is correct
99 Correct 157 ms 24080 KB Output is correct
100 Correct 233 ms 23916 KB Output is correct
101 Correct 265 ms 24556 KB Output is correct
102 Correct 292 ms 24556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 21996 KB Output is correct
2 Correct 22 ms 21996 KB Output is correct
3 Correct 22 ms 21996 KB Output is correct
4 Correct 22 ms 21996 KB Output is correct
5 Correct 18 ms 21996 KB Output is correct
6 Correct 18 ms 21996 KB Output is correct
7 Correct 24 ms 22144 KB Output is correct
8 Correct 26 ms 21996 KB Output is correct
9 Correct 26 ms 21996 KB Output is correct
10 Correct 26 ms 21996 KB Output is correct
11 Correct 23 ms 21996 KB Output is correct
12 Correct 24 ms 21996 KB Output is correct
13 Correct 18 ms 21996 KB Output is correct
14 Correct 20 ms 22144 KB Output is correct
15 Correct 22 ms 21996 KB Output is correct
16 Correct 23 ms 21996 KB Output is correct
17 Correct 24 ms 21996 KB Output is correct
18 Correct 23 ms 22036 KB Output is correct
19 Correct 22 ms 21996 KB Output is correct
20 Correct 27 ms 21996 KB Output is correct
21 Correct 23 ms 21996 KB Output is correct
22 Correct 23 ms 21996 KB Output is correct
23 Correct 22 ms 21996 KB Output is correct
24 Correct 22 ms 21996 KB Output is correct
25 Correct 20 ms 21996 KB Output is correct
26 Correct 19 ms 21996 KB Output is correct
27 Correct 23 ms 21996 KB Output is correct
28 Correct 26 ms 21996 KB Output is correct
29 Correct 22 ms 21996 KB Output is correct
30 Correct 24 ms 21996 KB Output is correct
31 Correct 24 ms 21996 KB Output is correct
32 Correct 24 ms 21996 KB Output is correct
33 Correct 19 ms 21996 KB Output is correct
34 Correct 21 ms 21996 KB Output is correct
35 Correct 22 ms 22028 KB Output is correct
36 Correct 23 ms 21996 KB Output is correct
37 Correct 26 ms 21996 KB Output is correct
38 Correct 22 ms 21996 KB Output is correct
39 Correct 309 ms 24944 KB Output is correct
40 Correct 333 ms 24988 KB Output is correct
41 Correct 306 ms 24972 KB Output is correct
42 Correct 315 ms 25068 KB Output is correct
43 Correct 324 ms 24940 KB Output is correct
44 Correct 309 ms 24900 KB Output is correct
45 Correct 173 ms 23528 KB Output is correct
46 Correct 180 ms 23620 KB Output is correct
47 Correct 378 ms 24940 KB Output is correct
48 Correct 380 ms 24940 KB Output is correct
49 Correct 393 ms 24940 KB Output is correct
50 Correct 364 ms 24940 KB Output is correct
51 Correct 234 ms 24556 KB Output is correct
52 Correct 270 ms 25068 KB Output is correct
53 Correct 287 ms 24732 KB Output is correct
54 Correct 273 ms 24940 KB Output is correct
55 Correct 966 ms 32696 KB Output is correct
56 Correct 755 ms 30572 KB Output is correct
57 Execution timed out 1028 ms 33672 KB Time limit exceeded
58 Halted 0 ms 0 KB -