Submission #386998

# Submission time Handle Problem Language Result Execution time Memory
386998 2021-04-07T19:16:39 Z AmineWeslati Food Court (JOI21_foodcourt) C++14
68 / 100
1000 ms 34668 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=500;
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 19 ms 21996 KB Output is correct
2 Correct 21 ms 21996 KB Output is correct
3 Correct 19 ms 21996 KB Output is correct
4 Correct 21 ms 22016 KB Output is correct
5 Correct 17 ms 22016 KB Output is correct
6 Correct 18 ms 21996 KB Output is correct
7 Correct 23 ms 21996 KB Output is correct
8 Correct 23 ms 21996 KB Output is correct
9 Correct 22 ms 21996 KB Output is correct
10 Correct 22 ms 21996 KB Output is correct
11 Correct 22 ms 21996 KB Output is correct
12 Correct 21 ms 21996 KB Output is correct
13 Correct 18 ms 21996 KB Output is correct
14 Correct 18 ms 21996 KB Output is correct
15 Correct 19 ms 21996 KB Output is correct
16 Correct 20 ms 21996 KB Output is correct
17 Correct 20 ms 21996 KB Output is correct
18 Correct 22 ms 21996 KB Output is correct
19 Correct 21 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 21996 KB Output is correct
2 Correct 21 ms 21996 KB Output is correct
3 Correct 19 ms 21996 KB Output is correct
4 Correct 21 ms 22016 KB Output is correct
5 Correct 17 ms 22016 KB Output is correct
6 Correct 18 ms 21996 KB Output is correct
7 Correct 23 ms 21996 KB Output is correct
8 Correct 23 ms 21996 KB Output is correct
9 Correct 22 ms 21996 KB Output is correct
10 Correct 22 ms 21996 KB Output is correct
11 Correct 22 ms 21996 KB Output is correct
12 Correct 21 ms 21996 KB Output is correct
13 Correct 18 ms 21996 KB Output is correct
14 Correct 18 ms 21996 KB Output is correct
15 Correct 19 ms 21996 KB Output is correct
16 Correct 20 ms 21996 KB Output is correct
17 Correct 20 ms 21996 KB Output is correct
18 Correct 22 ms 21996 KB Output is correct
19 Correct 21 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 21 ms 21996 KB Output is correct
22 Correct 21 ms 21996 KB Output is correct
23 Correct 20 ms 21996 KB Output is correct
24 Correct 21 ms 21996 KB Output is correct
25 Correct 20 ms 22124 KB Output is correct
26 Correct 19 ms 21996 KB Output is correct
27 Correct 23 ms 21996 KB Output is correct
28 Correct 23 ms 21996 KB Output is correct
29 Correct 21 ms 21996 KB Output is correct
30 Correct 22 ms 21996 KB Output is correct
31 Correct 22 ms 21996 KB Output is correct
32 Correct 22 ms 21996 KB Output is correct
33 Correct 18 ms 22000 KB Output is correct
34 Correct 18 ms 21996 KB Output is correct
35 Correct 19 ms 21996 KB Output is correct
36 Correct 21 ms 21996 KB Output is correct
37 Correct 19 ms 21996 KB Output is correct
38 Correct 21 ms 21996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 268 ms 25964 KB Output is correct
2 Correct 263 ms 25964 KB Output is correct
3 Correct 258 ms 26112 KB Output is correct
4 Correct 259 ms 26092 KB Output is correct
5 Correct 279 ms 26092 KB Output is correct
6 Correct 268 ms 25964 KB Output is correct
7 Correct 140 ms 24288 KB Output is correct
8 Correct 156 ms 24388 KB Output is correct
9 Correct 318 ms 25964 KB Output is correct
10 Correct 319 ms 25964 KB Output is correct
11 Correct 315 ms 25964 KB Output is correct
12 Correct 315 ms 25964 KB Output is correct
13 Correct 217 ms 25452 KB Output is correct
14 Correct 226 ms 25964 KB Output is correct
15 Correct 237 ms 25836 KB Output is correct
16 Correct 242 ms 25964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 884 ms 33772 KB Output is correct
2 Correct 685 ms 31468 KB Output is correct
3 Correct 972 ms 34668 KB Output is correct
4 Correct 708 ms 31852 KB Output is correct
5 Correct 735 ms 31544 KB Output is correct
6 Execution timed out 1025 ms 34628 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 21996 KB Output is correct
2 Correct 21 ms 21996 KB Output is correct
3 Correct 19 ms 21996 KB Output is correct
4 Correct 21 ms 22016 KB Output is correct
5 Correct 17 ms 22016 KB Output is correct
6 Correct 18 ms 21996 KB Output is correct
7 Correct 23 ms 21996 KB Output is correct
8 Correct 23 ms 21996 KB Output is correct
9 Correct 22 ms 21996 KB Output is correct
10 Correct 22 ms 21996 KB Output is correct
11 Correct 22 ms 21996 KB Output is correct
12 Correct 21 ms 21996 KB Output is correct
13 Correct 18 ms 21996 KB Output is correct
14 Correct 18 ms 21996 KB Output is correct
15 Correct 19 ms 21996 KB Output is correct
16 Correct 20 ms 21996 KB Output is correct
17 Correct 20 ms 21996 KB Output is correct
18 Correct 22 ms 21996 KB Output is correct
19 Correct 21 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 268 ms 25964 KB Output is correct
22 Correct 263 ms 25964 KB Output is correct
23 Correct 258 ms 26112 KB Output is correct
24 Correct 259 ms 26092 KB Output is correct
25 Correct 279 ms 26092 KB Output is correct
26 Correct 268 ms 25964 KB Output is correct
27 Correct 140 ms 24288 KB Output is correct
28 Correct 156 ms 24388 KB Output is correct
29 Correct 318 ms 25964 KB Output is correct
30 Correct 319 ms 25964 KB Output is correct
31 Correct 315 ms 25964 KB Output is correct
32 Correct 315 ms 25964 KB Output is correct
33 Correct 217 ms 25452 KB Output is correct
34 Correct 226 ms 25964 KB Output is correct
35 Correct 237 ms 25836 KB Output is correct
36 Correct 242 ms 25964 KB Output is correct
37 Correct 204 ms 25580 KB Output is correct
38 Correct 187 ms 25312 KB Output is correct
39 Correct 116 ms 23912 KB Output is correct
40 Correct 152 ms 24332 KB Output is correct
41 Correct 328 ms 26092 KB Output is correct
42 Correct 314 ms 25964 KB Output is correct
43 Correct 249 ms 25980 KB Output is correct
44 Correct 294 ms 25984 KB Output is correct
45 Correct 265 ms 25984 KB Output is correct
46 Correct 246 ms 25980 KB Output is correct
47 Correct 129 ms 24916 KB Output is correct
48 Correct 209 ms 25452 KB Output is correct
49 Correct 178 ms 24812 KB Output is correct
50 Correct 212 ms 25580 KB Output is correct
51 Correct 255 ms 25964 KB Output is correct
52 Correct 258 ms 26092 KB Output is correct
53 Correct 203 ms 25452 KB Output is correct
54 Correct 260 ms 25964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 25708 KB Output is correct
2 Correct 192 ms 25836 KB Output is correct
3 Correct 191 ms 26092 KB Output is correct
4 Correct 137 ms 25196 KB Output is correct
5 Correct 169 ms 25580 KB Output is correct
6 Correct 195 ms 26056 KB Output is correct
7 Correct 115 ms 24412 KB Output is correct
8 Correct 106 ms 24420 KB Output is correct
9 Correct 132 ms 25188 KB Output is correct
10 Correct 127 ms 24684 KB Output is correct
11 Correct 186 ms 25452 KB Output is correct
12 Correct 179 ms 25452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 21996 KB Output is correct
2 Correct 21 ms 21996 KB Output is correct
3 Correct 19 ms 21996 KB Output is correct
4 Correct 21 ms 22016 KB Output is correct
5 Correct 17 ms 22016 KB Output is correct
6 Correct 18 ms 21996 KB Output is correct
7 Correct 23 ms 21996 KB Output is correct
8 Correct 23 ms 21996 KB Output is correct
9 Correct 22 ms 21996 KB Output is correct
10 Correct 22 ms 21996 KB Output is correct
11 Correct 22 ms 21996 KB Output is correct
12 Correct 21 ms 21996 KB Output is correct
13 Correct 18 ms 21996 KB Output is correct
14 Correct 18 ms 21996 KB Output is correct
15 Correct 19 ms 21996 KB Output is correct
16 Correct 20 ms 21996 KB Output is correct
17 Correct 20 ms 21996 KB Output is correct
18 Correct 22 ms 21996 KB Output is correct
19 Correct 21 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 21 ms 21996 KB Output is correct
22 Correct 21 ms 21996 KB Output is correct
23 Correct 20 ms 21996 KB Output is correct
24 Correct 21 ms 21996 KB Output is correct
25 Correct 20 ms 22124 KB Output is correct
26 Correct 19 ms 21996 KB Output is correct
27 Correct 23 ms 21996 KB Output is correct
28 Correct 23 ms 21996 KB Output is correct
29 Correct 21 ms 21996 KB Output is correct
30 Correct 22 ms 21996 KB Output is correct
31 Correct 22 ms 21996 KB Output is correct
32 Correct 22 ms 21996 KB Output is correct
33 Correct 18 ms 22000 KB Output is correct
34 Correct 18 ms 21996 KB Output is correct
35 Correct 19 ms 21996 KB Output is correct
36 Correct 21 ms 21996 KB Output is correct
37 Correct 19 ms 21996 KB Output is correct
38 Correct 21 ms 21996 KB Output is correct
39 Correct 268 ms 25964 KB Output is correct
40 Correct 263 ms 25964 KB Output is correct
41 Correct 258 ms 26112 KB Output is correct
42 Correct 259 ms 26092 KB Output is correct
43 Correct 279 ms 26092 KB Output is correct
44 Correct 268 ms 25964 KB Output is correct
45 Correct 140 ms 24288 KB Output is correct
46 Correct 156 ms 24388 KB Output is correct
47 Correct 318 ms 25964 KB Output is correct
48 Correct 319 ms 25964 KB Output is correct
49 Correct 315 ms 25964 KB Output is correct
50 Correct 315 ms 25964 KB Output is correct
51 Correct 217 ms 25452 KB Output is correct
52 Correct 226 ms 25964 KB Output is correct
53 Correct 237 ms 25836 KB Output is correct
54 Correct 242 ms 25964 KB Output is correct
55 Correct 204 ms 25580 KB Output is correct
56 Correct 187 ms 25312 KB Output is correct
57 Correct 116 ms 23912 KB Output is correct
58 Correct 152 ms 24332 KB Output is correct
59 Correct 328 ms 26092 KB Output is correct
60 Correct 314 ms 25964 KB Output is correct
61 Correct 249 ms 25980 KB Output is correct
62 Correct 294 ms 25984 KB Output is correct
63 Correct 265 ms 25984 KB Output is correct
64 Correct 246 ms 25980 KB Output is correct
65 Correct 129 ms 24916 KB Output is correct
66 Correct 209 ms 25452 KB Output is correct
67 Correct 178 ms 24812 KB Output is correct
68 Correct 212 ms 25580 KB Output is correct
69 Correct 255 ms 25964 KB Output is correct
70 Correct 258 ms 26092 KB Output is correct
71 Correct 203 ms 25452 KB Output is correct
72 Correct 260 ms 25964 KB Output is correct
73 Correct 173 ms 25708 KB Output is correct
74 Correct 192 ms 25836 KB Output is correct
75 Correct 191 ms 26092 KB Output is correct
76 Correct 137 ms 25196 KB Output is correct
77 Correct 169 ms 25580 KB Output is correct
78 Correct 195 ms 26056 KB Output is correct
79 Correct 115 ms 24412 KB Output is correct
80 Correct 106 ms 24420 KB Output is correct
81 Correct 132 ms 25188 KB Output is correct
82 Correct 127 ms 24684 KB Output is correct
83 Correct 186 ms 25452 KB Output is correct
84 Correct 179 ms 25452 KB Output is correct
85 Correct 210 ms 25708 KB Output is correct
86 Correct 226 ms 26092 KB Output is correct
87 Correct 211 ms 25452 KB Output is correct
88 Correct 254 ms 25708 KB Output is correct
89 Correct 218 ms 24812 KB Output is correct
90 Correct 300 ms 25708 KB Output is correct
91 Correct 239 ms 25212 KB Output is correct
92 Correct 189 ms 24940 KB Output is correct
93 Correct 243 ms 25708 KB Output is correct
94 Correct 283 ms 25708 KB Output is correct
95 Correct 270 ms 25708 KB Output is correct
96 Correct 274 ms 25708 KB Output is correct
97 Correct 244 ms 25708 KB Output is correct
98 Correct 203 ms 25196 KB Output is correct
99 Correct 134 ms 24776 KB Output is correct
100 Correct 183 ms 24684 KB Output is correct
101 Correct 212 ms 25324 KB Output is correct
102 Correct 253 ms 25324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 21996 KB Output is correct
2 Correct 21 ms 21996 KB Output is correct
3 Correct 19 ms 21996 KB Output is correct
4 Correct 21 ms 22016 KB Output is correct
5 Correct 17 ms 22016 KB Output is correct
6 Correct 18 ms 21996 KB Output is correct
7 Correct 23 ms 21996 KB Output is correct
8 Correct 23 ms 21996 KB Output is correct
9 Correct 22 ms 21996 KB Output is correct
10 Correct 22 ms 21996 KB Output is correct
11 Correct 22 ms 21996 KB Output is correct
12 Correct 21 ms 21996 KB Output is correct
13 Correct 18 ms 21996 KB Output is correct
14 Correct 18 ms 21996 KB Output is correct
15 Correct 19 ms 21996 KB Output is correct
16 Correct 20 ms 21996 KB Output is correct
17 Correct 20 ms 21996 KB Output is correct
18 Correct 22 ms 21996 KB Output is correct
19 Correct 21 ms 21996 KB Output is correct
20 Correct 23 ms 21996 KB Output is correct
21 Correct 21 ms 21996 KB Output is correct
22 Correct 21 ms 21996 KB Output is correct
23 Correct 20 ms 21996 KB Output is correct
24 Correct 21 ms 21996 KB Output is correct
25 Correct 20 ms 22124 KB Output is correct
26 Correct 19 ms 21996 KB Output is correct
27 Correct 23 ms 21996 KB Output is correct
28 Correct 23 ms 21996 KB Output is correct
29 Correct 21 ms 21996 KB Output is correct
30 Correct 22 ms 21996 KB Output is correct
31 Correct 22 ms 21996 KB Output is correct
32 Correct 22 ms 21996 KB Output is correct
33 Correct 18 ms 22000 KB Output is correct
34 Correct 18 ms 21996 KB Output is correct
35 Correct 19 ms 21996 KB Output is correct
36 Correct 21 ms 21996 KB Output is correct
37 Correct 19 ms 21996 KB Output is correct
38 Correct 21 ms 21996 KB Output is correct
39 Correct 268 ms 25964 KB Output is correct
40 Correct 263 ms 25964 KB Output is correct
41 Correct 258 ms 26112 KB Output is correct
42 Correct 259 ms 26092 KB Output is correct
43 Correct 279 ms 26092 KB Output is correct
44 Correct 268 ms 25964 KB Output is correct
45 Correct 140 ms 24288 KB Output is correct
46 Correct 156 ms 24388 KB Output is correct
47 Correct 318 ms 25964 KB Output is correct
48 Correct 319 ms 25964 KB Output is correct
49 Correct 315 ms 25964 KB Output is correct
50 Correct 315 ms 25964 KB Output is correct
51 Correct 217 ms 25452 KB Output is correct
52 Correct 226 ms 25964 KB Output is correct
53 Correct 237 ms 25836 KB Output is correct
54 Correct 242 ms 25964 KB Output is correct
55 Correct 884 ms 33772 KB Output is correct
56 Correct 685 ms 31468 KB Output is correct
57 Correct 972 ms 34668 KB Output is correct
58 Correct 708 ms 31852 KB Output is correct
59 Correct 735 ms 31544 KB Output is correct
60 Execution timed out 1025 ms 34628 KB Time limit exceeded
61 Halted 0 ms 0 KB -