Submission #387000

# Submission time Handle Problem Language Result Execution time Memory
387000 2021-04-07T19:18:15 Z AmineWeslati Food Court (JOI21_foodcourt) C++14
68 / 100
1000 ms 32492 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=800;
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 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;

	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);
    	}
    	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 21 ms 21996 KB Output is correct
2 Correct 22 ms 21996 KB Output is correct
3 Correct 20 ms 21996 KB Output is correct
4 Correct 23 ms 22012 KB Output is correct
5 Correct 19 ms 21996 KB Output is correct
6 Correct 19 ms 21996 KB Output is correct
7 Correct 26 ms 21996 KB Output is correct
8 Correct 24 ms 21996 KB Output is correct
9 Correct 23 ms 21996 KB Output is correct
10 Correct 23 ms 21996 KB Output is correct
11 Correct 27 ms 21996 KB Output is correct
12 Correct 26 ms 21996 KB Output is correct
13 Correct 19 ms 21996 KB Output is correct
14 Correct 19 ms 21996 KB Output is correct
15 Correct 19 ms 21996 KB Output is correct
16 Correct 23 ms 21996 KB Output is correct
17 Correct 22 ms 21996 KB Output is correct
18 Correct 23 ms 21996 KB Output is correct
19 Correct 23 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 21996 KB Output is correct
2 Correct 22 ms 21996 KB Output is correct
3 Correct 20 ms 21996 KB Output is correct
4 Correct 23 ms 22012 KB Output is correct
5 Correct 19 ms 21996 KB Output is correct
6 Correct 19 ms 21996 KB Output is correct
7 Correct 26 ms 21996 KB Output is correct
8 Correct 24 ms 21996 KB Output is correct
9 Correct 23 ms 21996 KB Output is correct
10 Correct 23 ms 21996 KB Output is correct
11 Correct 27 ms 21996 KB Output is correct
12 Correct 26 ms 21996 KB Output is correct
13 Correct 19 ms 21996 KB Output is correct
14 Correct 19 ms 21996 KB Output is correct
15 Correct 19 ms 21996 KB Output is correct
16 Correct 23 ms 21996 KB Output is correct
17 Correct 22 ms 21996 KB Output is correct
18 Correct 23 ms 21996 KB Output is correct
19 Correct 23 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 22 ms 21996 KB Output is correct
22 Correct 24 ms 21996 KB Output is correct
23 Correct 22 ms 21996 KB Output is correct
24 Correct 23 ms 22048 KB Output is correct
25 Correct 18 ms 21996 KB Output is correct
26 Correct 21 ms 21996 KB Output is correct
27 Correct 25 ms 21996 KB Output is correct
28 Correct 26 ms 21996 KB Output is correct
29 Correct 23 ms 21996 KB Output is correct
30 Correct 24 ms 21996 KB Output is correct
31 Correct 23 ms 21996 KB Output is correct
32 Correct 23 ms 21996 KB Output is correct
33 Correct 19 ms 21996 KB Output is correct
34 Correct 19 ms 21996 KB Output is correct
35 Correct 21 ms 21996 KB Output is correct
36 Correct 23 ms 21996 KB Output is correct
37 Correct 21 ms 21996 KB Output is correct
38 Correct 28 ms 21996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 375 ms 24940 KB Output is correct
2 Correct 377 ms 25068 KB Output is correct
3 Correct 368 ms 24940 KB Output is correct
4 Correct 366 ms 25068 KB Output is correct
5 Correct 380 ms 25068 KB Output is correct
6 Correct 380 ms 25068 KB Output is correct
7 Correct 201 ms 23676 KB Output is correct
8 Correct 225 ms 23620 KB Output is correct
9 Correct 472 ms 25068 KB Output is correct
10 Correct 462 ms 24940 KB Output is correct
11 Correct 469 ms 25068 KB Output is correct
12 Correct 471 ms 24940 KB Output is correct
13 Correct 289 ms 24556 KB Output is correct
14 Correct 328 ms 25068 KB Output is correct
15 Correct 341 ms 24792 KB Output is correct
16 Correct 349 ms 25068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 32492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 21 ms 21996 KB Output is correct
2 Correct 22 ms 21996 KB Output is correct
3 Correct 20 ms 21996 KB Output is correct
4 Correct 23 ms 22012 KB Output is correct
5 Correct 19 ms 21996 KB Output is correct
6 Correct 19 ms 21996 KB Output is correct
7 Correct 26 ms 21996 KB Output is correct
8 Correct 24 ms 21996 KB Output is correct
9 Correct 23 ms 21996 KB Output is correct
10 Correct 23 ms 21996 KB Output is correct
11 Correct 27 ms 21996 KB Output is correct
12 Correct 26 ms 21996 KB Output is correct
13 Correct 19 ms 21996 KB Output is correct
14 Correct 19 ms 21996 KB Output is correct
15 Correct 19 ms 21996 KB Output is correct
16 Correct 23 ms 21996 KB Output is correct
17 Correct 22 ms 21996 KB Output is correct
18 Correct 23 ms 21996 KB Output is correct
19 Correct 23 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 375 ms 24940 KB Output is correct
22 Correct 377 ms 25068 KB Output is correct
23 Correct 368 ms 24940 KB Output is correct
24 Correct 366 ms 25068 KB Output is correct
25 Correct 380 ms 25068 KB Output is correct
26 Correct 380 ms 25068 KB Output is correct
27 Correct 201 ms 23676 KB Output is correct
28 Correct 225 ms 23620 KB Output is correct
29 Correct 472 ms 25068 KB Output is correct
30 Correct 462 ms 24940 KB Output is correct
31 Correct 469 ms 25068 KB Output is correct
32 Correct 471 ms 24940 KB Output is correct
33 Correct 289 ms 24556 KB Output is correct
34 Correct 328 ms 25068 KB Output is correct
35 Correct 341 ms 24792 KB Output is correct
36 Correct 349 ms 25068 KB Output is correct
37 Correct 280 ms 24684 KB Output is correct
38 Correct 269 ms 24428 KB Output is correct
39 Correct 165 ms 23528 KB Output is correct
40 Correct 227 ms 23692 KB Output is correct
41 Correct 476 ms 24964 KB Output is correct
42 Correct 436 ms 25068 KB Output is correct
43 Correct 331 ms 24940 KB Output is correct
44 Correct 418 ms 25068 KB Output is correct
45 Correct 389 ms 24960 KB Output is correct
46 Correct 335 ms 24956 KB Output is correct
47 Correct 171 ms 24020 KB Output is correct
48 Correct 296 ms 24496 KB Output is correct
49 Correct 244 ms 24044 KB Output is correct
50 Correct 311 ms 24684 KB Output is correct
51 Correct 349 ms 24940 KB Output is correct
52 Correct 350 ms 25068 KB Output is correct
53 Correct 276 ms 24300 KB Output is correct
54 Correct 345 ms 25068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 24684 KB Output is correct
2 Correct 253 ms 24940 KB Output is correct
3 Correct 263 ms 25068 KB Output is correct
4 Correct 183 ms 24172 KB Output is correct
5 Correct 230 ms 24556 KB Output is correct
6 Correct 258 ms 25068 KB Output is correct
7 Correct 127 ms 23388 KB Output is correct
8 Correct 137 ms 23396 KB Output is correct
9 Correct 156 ms 24164 KB Output is correct
10 Correct 168 ms 23788 KB Output is correct
11 Correct 243 ms 24300 KB Output is correct
12 Correct 240 ms 24428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 21996 KB Output is correct
2 Correct 22 ms 21996 KB Output is correct
3 Correct 20 ms 21996 KB Output is correct
4 Correct 23 ms 22012 KB Output is correct
5 Correct 19 ms 21996 KB Output is correct
6 Correct 19 ms 21996 KB Output is correct
7 Correct 26 ms 21996 KB Output is correct
8 Correct 24 ms 21996 KB Output is correct
9 Correct 23 ms 21996 KB Output is correct
10 Correct 23 ms 21996 KB Output is correct
11 Correct 27 ms 21996 KB Output is correct
12 Correct 26 ms 21996 KB Output is correct
13 Correct 19 ms 21996 KB Output is correct
14 Correct 19 ms 21996 KB Output is correct
15 Correct 19 ms 21996 KB Output is correct
16 Correct 23 ms 21996 KB Output is correct
17 Correct 22 ms 21996 KB Output is correct
18 Correct 23 ms 21996 KB Output is correct
19 Correct 23 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 22 ms 21996 KB Output is correct
22 Correct 24 ms 21996 KB Output is correct
23 Correct 22 ms 21996 KB Output is correct
24 Correct 23 ms 22048 KB Output is correct
25 Correct 18 ms 21996 KB Output is correct
26 Correct 21 ms 21996 KB Output is correct
27 Correct 25 ms 21996 KB Output is correct
28 Correct 26 ms 21996 KB Output is correct
29 Correct 23 ms 21996 KB Output is correct
30 Correct 24 ms 21996 KB Output is correct
31 Correct 23 ms 21996 KB Output is correct
32 Correct 23 ms 21996 KB Output is correct
33 Correct 19 ms 21996 KB Output is correct
34 Correct 19 ms 21996 KB Output is correct
35 Correct 21 ms 21996 KB Output is correct
36 Correct 23 ms 21996 KB Output is correct
37 Correct 21 ms 21996 KB Output is correct
38 Correct 28 ms 21996 KB Output is correct
39 Correct 375 ms 24940 KB Output is correct
40 Correct 377 ms 25068 KB Output is correct
41 Correct 368 ms 24940 KB Output is correct
42 Correct 366 ms 25068 KB Output is correct
43 Correct 380 ms 25068 KB Output is correct
44 Correct 380 ms 25068 KB Output is correct
45 Correct 201 ms 23676 KB Output is correct
46 Correct 225 ms 23620 KB Output is correct
47 Correct 472 ms 25068 KB Output is correct
48 Correct 462 ms 24940 KB Output is correct
49 Correct 469 ms 25068 KB Output is correct
50 Correct 471 ms 24940 KB Output is correct
51 Correct 289 ms 24556 KB Output is correct
52 Correct 328 ms 25068 KB Output is correct
53 Correct 341 ms 24792 KB Output is correct
54 Correct 349 ms 25068 KB Output is correct
55 Correct 280 ms 24684 KB Output is correct
56 Correct 269 ms 24428 KB Output is correct
57 Correct 165 ms 23528 KB Output is correct
58 Correct 227 ms 23692 KB Output is correct
59 Correct 476 ms 24964 KB Output is correct
60 Correct 436 ms 25068 KB Output is correct
61 Correct 331 ms 24940 KB Output is correct
62 Correct 418 ms 25068 KB Output is correct
63 Correct 389 ms 24960 KB Output is correct
64 Correct 335 ms 24956 KB Output is correct
65 Correct 171 ms 24020 KB Output is correct
66 Correct 296 ms 24496 KB Output is correct
67 Correct 244 ms 24044 KB Output is correct
68 Correct 311 ms 24684 KB Output is correct
69 Correct 349 ms 24940 KB Output is correct
70 Correct 350 ms 25068 KB Output is correct
71 Correct 276 ms 24300 KB Output is correct
72 Correct 345 ms 25068 KB Output is correct
73 Correct 226 ms 24684 KB Output is correct
74 Correct 253 ms 24940 KB Output is correct
75 Correct 263 ms 25068 KB Output is correct
76 Correct 183 ms 24172 KB Output is correct
77 Correct 230 ms 24556 KB Output is correct
78 Correct 258 ms 25068 KB Output is correct
79 Correct 127 ms 23388 KB Output is correct
80 Correct 137 ms 23396 KB Output is correct
81 Correct 156 ms 24164 KB Output is correct
82 Correct 168 ms 23788 KB Output is correct
83 Correct 243 ms 24300 KB Output is correct
84 Correct 240 ms 24428 KB Output is correct
85 Correct 279 ms 24684 KB Output is correct
86 Correct 310 ms 24976 KB Output is correct
87 Correct 288 ms 24684 KB Output is correct
88 Correct 323 ms 24972 KB Output is correct
89 Correct 313 ms 24044 KB Output is correct
90 Correct 424 ms 24940 KB Output is correct
91 Correct 337 ms 24300 KB Output is correct
92 Correct 263 ms 24172 KB Output is correct
93 Correct 332 ms 25068 KB Output is correct
94 Correct 405 ms 25088 KB Output is correct
95 Correct 371 ms 25196 KB Output is correct
96 Correct 381 ms 25452 KB Output is correct
97 Correct 350 ms 25416 KB Output is correct
98 Correct 290 ms 24848 KB Output is correct
99 Correct 176 ms 24648 KB Output is correct
100 Correct 260 ms 24556 KB Output is correct
101 Correct 302 ms 25196 KB Output is correct
102 Correct 368 ms 25324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 21996 KB Output is correct
2 Correct 22 ms 21996 KB Output is correct
3 Correct 20 ms 21996 KB Output is correct
4 Correct 23 ms 22012 KB Output is correct
5 Correct 19 ms 21996 KB Output is correct
6 Correct 19 ms 21996 KB Output is correct
7 Correct 26 ms 21996 KB Output is correct
8 Correct 24 ms 21996 KB Output is correct
9 Correct 23 ms 21996 KB Output is correct
10 Correct 23 ms 21996 KB Output is correct
11 Correct 27 ms 21996 KB Output is correct
12 Correct 26 ms 21996 KB Output is correct
13 Correct 19 ms 21996 KB Output is correct
14 Correct 19 ms 21996 KB Output is correct
15 Correct 19 ms 21996 KB Output is correct
16 Correct 23 ms 21996 KB Output is correct
17 Correct 22 ms 21996 KB Output is correct
18 Correct 23 ms 21996 KB Output is correct
19 Correct 23 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 22 ms 21996 KB Output is correct
22 Correct 24 ms 21996 KB Output is correct
23 Correct 22 ms 21996 KB Output is correct
24 Correct 23 ms 22048 KB Output is correct
25 Correct 18 ms 21996 KB Output is correct
26 Correct 21 ms 21996 KB Output is correct
27 Correct 25 ms 21996 KB Output is correct
28 Correct 26 ms 21996 KB Output is correct
29 Correct 23 ms 21996 KB Output is correct
30 Correct 24 ms 21996 KB Output is correct
31 Correct 23 ms 21996 KB Output is correct
32 Correct 23 ms 21996 KB Output is correct
33 Correct 19 ms 21996 KB Output is correct
34 Correct 19 ms 21996 KB Output is correct
35 Correct 21 ms 21996 KB Output is correct
36 Correct 23 ms 21996 KB Output is correct
37 Correct 21 ms 21996 KB Output is correct
38 Correct 28 ms 21996 KB Output is correct
39 Correct 375 ms 24940 KB Output is correct
40 Correct 377 ms 25068 KB Output is correct
41 Correct 368 ms 24940 KB Output is correct
42 Correct 366 ms 25068 KB Output is correct
43 Correct 380 ms 25068 KB Output is correct
44 Correct 380 ms 25068 KB Output is correct
45 Correct 201 ms 23676 KB Output is correct
46 Correct 225 ms 23620 KB Output is correct
47 Correct 472 ms 25068 KB Output is correct
48 Correct 462 ms 24940 KB Output is correct
49 Correct 469 ms 25068 KB Output is correct
50 Correct 471 ms 24940 KB Output is correct
51 Correct 289 ms 24556 KB Output is correct
52 Correct 328 ms 25068 KB Output is correct
53 Correct 341 ms 24792 KB Output is correct
54 Correct 349 ms 25068 KB Output is correct
55 Execution timed out 1086 ms 32492 KB Time limit exceeded
56 Halted 0 ms 0 KB -