답안 #387004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387004 2021-04-07T19:22:55 Z AmineWeslati 푸드 코트 (JOI21_foodcourt) C++14
68 / 100
1000 ms 39732 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=350;
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:115:12: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
  115 |  return C[i];
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 21996 KB Output is correct
2 Correct 20 ms 21996 KB Output is correct
3 Correct 18 ms 21996 KB Output is correct
4 Correct 20 ms 22124 KB Output is correct
5 Correct 17 ms 21996 KB Output is correct
6 Correct 18 ms 22124 KB Output is correct
7 Correct 22 ms 21996 KB Output is correct
8 Correct 20 ms 21996 KB Output is correct
9 Correct 20 ms 21996 KB Output is correct
10 Correct 20 ms 21996 KB Output is correct
11 Correct 20 ms 21996 KB Output is correct
12 Correct 20 ms 21996 KB Output is correct
13 Correct 17 ms 21996 KB Output is correct
14 Correct 17 ms 21996 KB Output is correct
15 Correct 18 ms 21996 KB Output is correct
16 Correct 19 ms 21996 KB Output is correct
17 Correct 19 ms 21996 KB Output is correct
18 Correct 19 ms 21996 KB Output is correct
19 Correct 19 ms 21996 KB Output is correct
20 Correct 20 ms 21996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 21996 KB Output is correct
2 Correct 20 ms 21996 KB Output is correct
3 Correct 18 ms 21996 KB Output is correct
4 Correct 20 ms 22124 KB Output is correct
5 Correct 17 ms 21996 KB Output is correct
6 Correct 18 ms 22124 KB Output is correct
7 Correct 22 ms 21996 KB Output is correct
8 Correct 20 ms 21996 KB Output is correct
9 Correct 20 ms 21996 KB Output is correct
10 Correct 20 ms 21996 KB Output is correct
11 Correct 20 ms 21996 KB Output is correct
12 Correct 20 ms 21996 KB Output is correct
13 Correct 17 ms 21996 KB Output is correct
14 Correct 17 ms 21996 KB Output is correct
15 Correct 18 ms 21996 KB Output is correct
16 Correct 19 ms 21996 KB Output is correct
17 Correct 19 ms 21996 KB Output is correct
18 Correct 19 ms 21996 KB Output is correct
19 Correct 19 ms 21996 KB Output is correct
20 Correct 20 ms 21996 KB Output is correct
21 Correct 19 ms 21996 KB Output is correct
22 Correct 20 ms 21996 KB Output is correct
23 Correct 19 ms 21996 KB Output is correct
24 Correct 19 ms 21996 KB Output is correct
25 Correct 17 ms 21996 KB Output is correct
26 Correct 17 ms 21996 KB Output is correct
27 Correct 21 ms 21996 KB Output is correct
28 Correct 21 ms 21996 KB Output is correct
29 Correct 20 ms 21996 KB Output is correct
30 Correct 21 ms 21996 KB Output is correct
31 Correct 20 ms 21996 KB Output is correct
32 Correct 21 ms 21996 KB Output is correct
33 Correct 17 ms 21996 KB Output is correct
34 Correct 17 ms 21996 KB Output is correct
35 Correct 19 ms 21996 KB Output is correct
36 Correct 20 ms 21996 KB Output is correct
37 Correct 18 ms 21996 KB Output is correct
38 Correct 20 ms 21996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 212 ms 25452 KB Output is correct
2 Correct 238 ms 25452 KB Output is correct
3 Correct 204 ms 25324 KB Output is correct
4 Correct 201 ms 25324 KB Output is correct
5 Correct 211 ms 25592 KB Output is correct
6 Correct 208 ms 25600 KB Output is correct
7 Correct 110 ms 23784 KB Output is correct
8 Correct 126 ms 23876 KB Output is correct
9 Correct 244 ms 25452 KB Output is correct
10 Correct 252 ms 25520 KB Output is correct
11 Correct 247 ms 25580 KB Output is correct
12 Correct 245 ms 25580 KB Output is correct
13 Correct 158 ms 24684 KB Output is correct
14 Correct 178 ms 25324 KB Output is correct
15 Correct 186 ms 25196 KB Output is correct
16 Correct 191 ms 25452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 731 ms 33220 KB Output is correct
2 Correct 585 ms 32364 KB Output is correct
3 Correct 826 ms 35308 KB Output is correct
4 Correct 575 ms 32620 KB Output is correct
5 Correct 587 ms 32368 KB Output is correct
6 Correct 825 ms 35348 KB Output is correct
7 Correct 386 ms 32672 KB Output is correct
8 Correct 437 ms 32332 KB Output is correct
9 Correct 736 ms 39404 KB Output is correct
10 Correct 752 ms 39532 KB Output is correct
11 Execution timed out 1081 ms 39732 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 21996 KB Output is correct
2 Correct 20 ms 21996 KB Output is correct
3 Correct 18 ms 21996 KB Output is correct
4 Correct 20 ms 22124 KB Output is correct
5 Correct 17 ms 21996 KB Output is correct
6 Correct 18 ms 22124 KB Output is correct
7 Correct 22 ms 21996 KB Output is correct
8 Correct 20 ms 21996 KB Output is correct
9 Correct 20 ms 21996 KB Output is correct
10 Correct 20 ms 21996 KB Output is correct
11 Correct 20 ms 21996 KB Output is correct
12 Correct 20 ms 21996 KB Output is correct
13 Correct 17 ms 21996 KB Output is correct
14 Correct 17 ms 21996 KB Output is correct
15 Correct 18 ms 21996 KB Output is correct
16 Correct 19 ms 21996 KB Output is correct
17 Correct 19 ms 21996 KB Output is correct
18 Correct 19 ms 21996 KB Output is correct
19 Correct 19 ms 21996 KB Output is correct
20 Correct 20 ms 21996 KB Output is correct
21 Correct 212 ms 25452 KB Output is correct
22 Correct 238 ms 25452 KB Output is correct
23 Correct 204 ms 25324 KB Output is correct
24 Correct 201 ms 25324 KB Output is correct
25 Correct 211 ms 25592 KB Output is correct
26 Correct 208 ms 25600 KB Output is correct
27 Correct 110 ms 23784 KB Output is correct
28 Correct 126 ms 23876 KB Output is correct
29 Correct 244 ms 25452 KB Output is correct
30 Correct 252 ms 25520 KB Output is correct
31 Correct 247 ms 25580 KB Output is correct
32 Correct 245 ms 25580 KB Output is correct
33 Correct 158 ms 24684 KB Output is correct
34 Correct 178 ms 25324 KB Output is correct
35 Correct 186 ms 25196 KB Output is correct
36 Correct 191 ms 25452 KB Output is correct
37 Correct 159 ms 24940 KB Output is correct
38 Correct 149 ms 24684 KB Output is correct
39 Correct 90 ms 23656 KB Output is correct
40 Correct 117 ms 23948 KB Output is correct
41 Correct 253 ms 25452 KB Output is correct
42 Correct 222 ms 25324 KB Output is correct
43 Correct 191 ms 25324 KB Output is correct
44 Correct 229 ms 25452 KB Output is correct
45 Correct 207 ms 25324 KB Output is correct
46 Correct 190 ms 25324 KB Output is correct
47 Correct 105 ms 24276 KB Output is correct
48 Correct 166 ms 24784 KB Output is correct
49 Correct 153 ms 24300 KB Output is correct
50 Correct 168 ms 24812 KB Output is correct
51 Correct 194 ms 25324 KB Output is correct
52 Correct 194 ms 25324 KB Output is correct
53 Correct 171 ms 24556 KB Output is correct
54 Correct 187 ms 25580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 25196 KB Output is correct
2 Correct 165 ms 25324 KB Output is correct
3 Correct 162 ms 25580 KB Output is correct
4 Correct 113 ms 24556 KB Output is correct
5 Correct 138 ms 25068 KB Output is correct
6 Correct 163 ms 25452 KB Output is correct
7 Correct 87 ms 23772 KB Output is correct
8 Correct 92 ms 23652 KB Output is correct
9 Correct 106 ms 24676 KB Output is correct
10 Correct 106 ms 24044 KB Output is correct
11 Correct 154 ms 24812 KB Output is correct
12 Correct 146 ms 24940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 21996 KB Output is correct
2 Correct 20 ms 21996 KB Output is correct
3 Correct 18 ms 21996 KB Output is correct
4 Correct 20 ms 22124 KB Output is correct
5 Correct 17 ms 21996 KB Output is correct
6 Correct 18 ms 22124 KB Output is correct
7 Correct 22 ms 21996 KB Output is correct
8 Correct 20 ms 21996 KB Output is correct
9 Correct 20 ms 21996 KB Output is correct
10 Correct 20 ms 21996 KB Output is correct
11 Correct 20 ms 21996 KB Output is correct
12 Correct 20 ms 21996 KB Output is correct
13 Correct 17 ms 21996 KB Output is correct
14 Correct 17 ms 21996 KB Output is correct
15 Correct 18 ms 21996 KB Output is correct
16 Correct 19 ms 21996 KB Output is correct
17 Correct 19 ms 21996 KB Output is correct
18 Correct 19 ms 21996 KB Output is correct
19 Correct 19 ms 21996 KB Output is correct
20 Correct 20 ms 21996 KB Output is correct
21 Correct 19 ms 21996 KB Output is correct
22 Correct 20 ms 21996 KB Output is correct
23 Correct 19 ms 21996 KB Output is correct
24 Correct 19 ms 21996 KB Output is correct
25 Correct 17 ms 21996 KB Output is correct
26 Correct 17 ms 21996 KB Output is correct
27 Correct 21 ms 21996 KB Output is correct
28 Correct 21 ms 21996 KB Output is correct
29 Correct 20 ms 21996 KB Output is correct
30 Correct 21 ms 21996 KB Output is correct
31 Correct 20 ms 21996 KB Output is correct
32 Correct 21 ms 21996 KB Output is correct
33 Correct 17 ms 21996 KB Output is correct
34 Correct 17 ms 21996 KB Output is correct
35 Correct 19 ms 21996 KB Output is correct
36 Correct 20 ms 21996 KB Output is correct
37 Correct 18 ms 21996 KB Output is correct
38 Correct 20 ms 21996 KB Output is correct
39 Correct 212 ms 25452 KB Output is correct
40 Correct 238 ms 25452 KB Output is correct
41 Correct 204 ms 25324 KB Output is correct
42 Correct 201 ms 25324 KB Output is correct
43 Correct 211 ms 25592 KB Output is correct
44 Correct 208 ms 25600 KB Output is correct
45 Correct 110 ms 23784 KB Output is correct
46 Correct 126 ms 23876 KB Output is correct
47 Correct 244 ms 25452 KB Output is correct
48 Correct 252 ms 25520 KB Output is correct
49 Correct 247 ms 25580 KB Output is correct
50 Correct 245 ms 25580 KB Output is correct
51 Correct 158 ms 24684 KB Output is correct
52 Correct 178 ms 25324 KB Output is correct
53 Correct 186 ms 25196 KB Output is correct
54 Correct 191 ms 25452 KB Output is correct
55 Correct 159 ms 24940 KB Output is correct
56 Correct 149 ms 24684 KB Output is correct
57 Correct 90 ms 23656 KB Output is correct
58 Correct 117 ms 23948 KB Output is correct
59 Correct 253 ms 25452 KB Output is correct
60 Correct 222 ms 25324 KB Output is correct
61 Correct 191 ms 25324 KB Output is correct
62 Correct 229 ms 25452 KB Output is correct
63 Correct 207 ms 25324 KB Output is correct
64 Correct 190 ms 25324 KB Output is correct
65 Correct 105 ms 24276 KB Output is correct
66 Correct 166 ms 24784 KB Output is correct
67 Correct 153 ms 24300 KB Output is correct
68 Correct 168 ms 24812 KB Output is correct
69 Correct 194 ms 25324 KB Output is correct
70 Correct 194 ms 25324 KB Output is correct
71 Correct 171 ms 24556 KB Output is correct
72 Correct 187 ms 25580 KB Output is correct
73 Correct 147 ms 25196 KB Output is correct
74 Correct 165 ms 25324 KB Output is correct
75 Correct 162 ms 25580 KB Output is correct
76 Correct 113 ms 24556 KB Output is correct
77 Correct 138 ms 25068 KB Output is correct
78 Correct 163 ms 25452 KB Output is correct
79 Correct 87 ms 23772 KB Output is correct
80 Correct 92 ms 23652 KB Output is correct
81 Correct 106 ms 24676 KB Output is correct
82 Correct 106 ms 24044 KB Output is correct
83 Correct 154 ms 24812 KB Output is correct
84 Correct 146 ms 24940 KB Output is correct
85 Correct 165 ms 25196 KB Output is correct
86 Correct 186 ms 25580 KB Output is correct
87 Correct 162 ms 25196 KB Output is correct
88 Correct 192 ms 25452 KB Output is correct
89 Correct 168 ms 24556 KB Output is correct
90 Correct 232 ms 25452 KB Output is correct
91 Correct 183 ms 24940 KB Output is correct
92 Correct 154 ms 24684 KB Output is correct
93 Correct 198 ms 25452 KB Output is correct
94 Correct 221 ms 25460 KB Output is correct
95 Correct 212 ms 24940 KB Output is correct
96 Correct 221 ms 25032 KB Output is correct
97 Correct 202 ms 24940 KB Output is correct
98 Correct 163 ms 24428 KB Output is correct
99 Correct 109 ms 24008 KB Output is correct
100 Correct 147 ms 23920 KB Output is correct
101 Correct 175 ms 24556 KB Output is correct
102 Correct 200 ms 24592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 21996 KB Output is correct
2 Correct 20 ms 21996 KB Output is correct
3 Correct 18 ms 21996 KB Output is correct
4 Correct 20 ms 22124 KB Output is correct
5 Correct 17 ms 21996 KB Output is correct
6 Correct 18 ms 22124 KB Output is correct
7 Correct 22 ms 21996 KB Output is correct
8 Correct 20 ms 21996 KB Output is correct
9 Correct 20 ms 21996 KB Output is correct
10 Correct 20 ms 21996 KB Output is correct
11 Correct 20 ms 21996 KB Output is correct
12 Correct 20 ms 21996 KB Output is correct
13 Correct 17 ms 21996 KB Output is correct
14 Correct 17 ms 21996 KB Output is correct
15 Correct 18 ms 21996 KB Output is correct
16 Correct 19 ms 21996 KB Output is correct
17 Correct 19 ms 21996 KB Output is correct
18 Correct 19 ms 21996 KB Output is correct
19 Correct 19 ms 21996 KB Output is correct
20 Correct 20 ms 21996 KB Output is correct
21 Correct 19 ms 21996 KB Output is correct
22 Correct 20 ms 21996 KB Output is correct
23 Correct 19 ms 21996 KB Output is correct
24 Correct 19 ms 21996 KB Output is correct
25 Correct 17 ms 21996 KB Output is correct
26 Correct 17 ms 21996 KB Output is correct
27 Correct 21 ms 21996 KB Output is correct
28 Correct 21 ms 21996 KB Output is correct
29 Correct 20 ms 21996 KB Output is correct
30 Correct 21 ms 21996 KB Output is correct
31 Correct 20 ms 21996 KB Output is correct
32 Correct 21 ms 21996 KB Output is correct
33 Correct 17 ms 21996 KB Output is correct
34 Correct 17 ms 21996 KB Output is correct
35 Correct 19 ms 21996 KB Output is correct
36 Correct 20 ms 21996 KB Output is correct
37 Correct 18 ms 21996 KB Output is correct
38 Correct 20 ms 21996 KB Output is correct
39 Correct 212 ms 25452 KB Output is correct
40 Correct 238 ms 25452 KB Output is correct
41 Correct 204 ms 25324 KB Output is correct
42 Correct 201 ms 25324 KB Output is correct
43 Correct 211 ms 25592 KB Output is correct
44 Correct 208 ms 25600 KB Output is correct
45 Correct 110 ms 23784 KB Output is correct
46 Correct 126 ms 23876 KB Output is correct
47 Correct 244 ms 25452 KB Output is correct
48 Correct 252 ms 25520 KB Output is correct
49 Correct 247 ms 25580 KB Output is correct
50 Correct 245 ms 25580 KB Output is correct
51 Correct 158 ms 24684 KB Output is correct
52 Correct 178 ms 25324 KB Output is correct
53 Correct 186 ms 25196 KB Output is correct
54 Correct 191 ms 25452 KB Output is correct
55 Correct 731 ms 33220 KB Output is correct
56 Correct 585 ms 32364 KB Output is correct
57 Correct 826 ms 35308 KB Output is correct
58 Correct 575 ms 32620 KB Output is correct
59 Correct 587 ms 32368 KB Output is correct
60 Correct 825 ms 35348 KB Output is correct
61 Correct 386 ms 32672 KB Output is correct
62 Correct 437 ms 32332 KB Output is correct
63 Correct 736 ms 39404 KB Output is correct
64 Correct 752 ms 39532 KB Output is correct
65 Execution timed out 1081 ms 39732 KB Time limit exceeded
66 Halted 0 ms 0 KB -