#include <bits/stdc++.h>
using namespace std;
#include <ext/rope>
using namespace __gnu_cxx;
// #pragma comment(linker, "/stack:2000000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define precise(a) cout<<fixed<<setprecision(a)
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
// t1
const ll mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353; // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const ll N = ll(3e5)+10;
const ll K = 17;
const ll inf = 1e18;
const ld eps = 1e-15L;
//const ll B = 316;
ll lcm(ll a, ll b){ return (a / __gcd(a,b)) * b; }
//const ld P = acos(-1.0);
// ll binpow(ll a, ll b, ll m){ ll res=1;a%=m; while(b>0){ if(b&1)res=(res*a)%m; a=(a*a)%m; b/=2; } return res%m;}
ld binpow(ld a, ll b){ ld res=1; while(b>0){ if(b&1)res=(res*a); a=(a*a); b/=2; } return res;}
void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
void precalc() {
}
ll n, m, q;
ll t[N*4], u[N*4];
vector<pll>cus[N];
ll debt[N];
void push(ll v, ll tl, ll tr) {
if(u[v]) {
t[v] = max(0ll, t[v]+(tr-tl+1)*u[v]);
if(tl!=tr) {
u[v+v] = u[v];
u[v+v+1] = u[v];
}
u[v] = 0;
}
}
void update(ll v, ll tl, ll tr, ll l, ll r, ll x) {
push(v, tl, tr);
if(tl>r || l>tr) return;
if(l<=tl && tr<=r) {
u[v]+=x;
push(v, tl, tr);
return;
}
ll tm = (tl+tr)/2;
update(v+v, tl, tm, l, r, x);
update(v+v+1, tm+1, tr, l, r, x);
t[v] = t[v+v] + t[v+v+1];
}
ll get(ll v, ll tl, ll tr, ll l, ll r) {
push(v, tl, tr);
if(tl>r || l>tr) return 0;
if(l<=tl && tr<=r) return t[v];
ll tm = (tl+tr)/2;
return get(v+v, tl, tm, l, r) + get(v+v+1, tm+1, tr, l, r);
}
void Baizho()
{
cin>>n>>m>>q;
if(m==1) {
while(q--) {
ll t; cin>>t;
if(t==1) {
ll l, r, shop, k; cin>>l>>r>>shop>>k;
update(1, 1, n, l, r, k);
}
else if(t==2) {
ll l, r, k; cin>>l>>r>>k;
update(1, 1, n, l, r, -k);
}
else {
ll shop, pos; cin>>shop>>pos;
ll cnt = get(1, 1, n, shop, shop);
if(cnt<pos) cout<<"0\n";
else cout<<"1\n";
}
}
return;
}
while(q--) {
ll t; cin>>t;
if(t==1) {
ll l, r, shop, k; cin>>l>>r>>shop>>k;
for(ll i=l; i<=r; i++) {
ll extra = 0;
if(cus[i].sz) {
extra = cus[i].back().ff;
if(cus[i].back().ss==shop) {
cus[i].pop_back();
}
}
cus[i].pb({k+extra, shop});
}
}
else if(t==2) {
ll l, r, k; cin>>l>>r>>k;
for(ll i=l; i<=r; i++) {
if(cus[i].sz) debt[i]+=min(cus[i].back().ff-debt[i], k);
}
}
else {
ll shop, pos; cin>>shop>>pos;
pos+=debt[shop];
if(cus[shop].sz==0) cout<<"0\n";
else if(pos>cus[shop].back().ff) cout<<"0\n";
else cout<<(*lower_bound(all(cus[shop]), make_pair(pos, 0ll))).ss<<"\n";
}
}
}
int main() {
// Freopen("div7");
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
precalc();
int ttt = 1;
// cin>>ttt;
for(int i=1; i<=ttt; i++) { Baizho();}
}
Compilation message
foodcourt.cpp: In function 'void Freopen(std::string)':
foodcourt.cpp:37:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:37:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
13140 KB |
Output is correct |
2 |
Correct |
22 ms |
18816 KB |
Output is correct |
3 |
Correct |
21 ms |
20692 KB |
Output is correct |
4 |
Correct |
33 ms |
31372 KB |
Output is correct |
5 |
Correct |
4 ms |
7420 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
26 ms |
24776 KB |
Output is correct |
8 |
Correct |
26 ms |
24256 KB |
Output is correct |
9 |
Correct |
29 ms |
24464 KB |
Output is correct |
10 |
Correct |
27 ms |
25300 KB |
Output is correct |
11 |
Correct |
27 ms |
25756 KB |
Output is correct |
12 |
Correct |
35 ms |
24772 KB |
Output is correct |
13 |
Correct |
45 ms |
33144 KB |
Output is correct |
14 |
Correct |
55 ms |
38272 KB |
Output is correct |
15 |
Correct |
34 ms |
22900 KB |
Output is correct |
16 |
Correct |
46 ms |
37960 KB |
Output is correct |
17 |
Correct |
16 ms |
16340 KB |
Output is correct |
18 |
Correct |
23 ms |
21128 KB |
Output is correct |
19 |
Correct |
5 ms |
7636 KB |
Output is correct |
20 |
Correct |
5 ms |
7636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
13140 KB |
Output is correct |
2 |
Correct |
22 ms |
18816 KB |
Output is correct |
3 |
Correct |
21 ms |
20692 KB |
Output is correct |
4 |
Correct |
33 ms |
31372 KB |
Output is correct |
5 |
Correct |
4 ms |
7420 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
26 ms |
24776 KB |
Output is correct |
8 |
Correct |
26 ms |
24256 KB |
Output is correct |
9 |
Correct |
29 ms |
24464 KB |
Output is correct |
10 |
Correct |
27 ms |
25300 KB |
Output is correct |
11 |
Correct |
27 ms |
25756 KB |
Output is correct |
12 |
Correct |
35 ms |
24772 KB |
Output is correct |
13 |
Correct |
45 ms |
33144 KB |
Output is correct |
14 |
Correct |
55 ms |
38272 KB |
Output is correct |
15 |
Correct |
34 ms |
22900 KB |
Output is correct |
16 |
Correct |
46 ms |
37960 KB |
Output is correct |
17 |
Correct |
16 ms |
16340 KB |
Output is correct |
18 |
Correct |
23 ms |
21128 KB |
Output is correct |
19 |
Correct |
5 ms |
7636 KB |
Output is correct |
20 |
Correct |
5 ms |
7636 KB |
Output is correct |
21 |
Correct |
17 ms |
17668 KB |
Output is correct |
22 |
Correct |
18 ms |
18848 KB |
Output is correct |
23 |
Correct |
25 ms |
22896 KB |
Output is correct |
24 |
Correct |
30 ms |
31324 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
4 ms |
7380 KB |
Output is correct |
27 |
Correct |
25 ms |
22092 KB |
Output is correct |
28 |
Correct |
27 ms |
25116 KB |
Output is correct |
29 |
Correct |
28 ms |
25144 KB |
Output is correct |
30 |
Correct |
28 ms |
24584 KB |
Output is correct |
31 |
Correct |
25 ms |
21684 KB |
Output is correct |
32 |
Correct |
31 ms |
21460 KB |
Output is correct |
33 |
Correct |
43 ms |
31572 KB |
Output is correct |
34 |
Correct |
43 ms |
38120 KB |
Output is correct |
35 |
Correct |
29 ms |
30100 KB |
Output is correct |
36 |
Correct |
43 ms |
37736 KB |
Output is correct |
37 |
Correct |
5 ms |
7508 KB |
Output is correct |
38 |
Correct |
5 ms |
7636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
10800 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
220 ms |
15728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
13140 KB |
Output is correct |
2 |
Correct |
22 ms |
18816 KB |
Output is correct |
3 |
Correct |
21 ms |
20692 KB |
Output is correct |
4 |
Correct |
33 ms |
31372 KB |
Output is correct |
5 |
Correct |
4 ms |
7420 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
26 ms |
24776 KB |
Output is correct |
8 |
Correct |
26 ms |
24256 KB |
Output is correct |
9 |
Correct |
29 ms |
24464 KB |
Output is correct |
10 |
Correct |
27 ms |
25300 KB |
Output is correct |
11 |
Correct |
27 ms |
25756 KB |
Output is correct |
12 |
Correct |
35 ms |
24772 KB |
Output is correct |
13 |
Correct |
45 ms |
33144 KB |
Output is correct |
14 |
Correct |
55 ms |
38272 KB |
Output is correct |
15 |
Correct |
34 ms |
22900 KB |
Output is correct |
16 |
Correct |
46 ms |
37960 KB |
Output is correct |
17 |
Correct |
16 ms |
16340 KB |
Output is correct |
18 |
Correct |
23 ms |
21128 KB |
Output is correct |
19 |
Correct |
5 ms |
7636 KB |
Output is correct |
20 |
Correct |
5 ms |
7636 KB |
Output is correct |
21 |
Execution timed out |
1094 ms |
10800 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
805 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
13140 KB |
Output is correct |
2 |
Correct |
22 ms |
18816 KB |
Output is correct |
3 |
Correct |
21 ms |
20692 KB |
Output is correct |
4 |
Correct |
33 ms |
31372 KB |
Output is correct |
5 |
Correct |
4 ms |
7420 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
26 ms |
24776 KB |
Output is correct |
8 |
Correct |
26 ms |
24256 KB |
Output is correct |
9 |
Correct |
29 ms |
24464 KB |
Output is correct |
10 |
Correct |
27 ms |
25300 KB |
Output is correct |
11 |
Correct |
27 ms |
25756 KB |
Output is correct |
12 |
Correct |
35 ms |
24772 KB |
Output is correct |
13 |
Correct |
45 ms |
33144 KB |
Output is correct |
14 |
Correct |
55 ms |
38272 KB |
Output is correct |
15 |
Correct |
34 ms |
22900 KB |
Output is correct |
16 |
Correct |
46 ms |
37960 KB |
Output is correct |
17 |
Correct |
16 ms |
16340 KB |
Output is correct |
18 |
Correct |
23 ms |
21128 KB |
Output is correct |
19 |
Correct |
5 ms |
7636 KB |
Output is correct |
20 |
Correct |
5 ms |
7636 KB |
Output is correct |
21 |
Correct |
17 ms |
17668 KB |
Output is correct |
22 |
Correct |
18 ms |
18848 KB |
Output is correct |
23 |
Correct |
25 ms |
22896 KB |
Output is correct |
24 |
Correct |
30 ms |
31324 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
4 ms |
7380 KB |
Output is correct |
27 |
Correct |
25 ms |
22092 KB |
Output is correct |
28 |
Correct |
27 ms |
25116 KB |
Output is correct |
29 |
Correct |
28 ms |
25144 KB |
Output is correct |
30 |
Correct |
28 ms |
24584 KB |
Output is correct |
31 |
Correct |
25 ms |
21684 KB |
Output is correct |
32 |
Correct |
31 ms |
21460 KB |
Output is correct |
33 |
Correct |
43 ms |
31572 KB |
Output is correct |
34 |
Correct |
43 ms |
38120 KB |
Output is correct |
35 |
Correct |
29 ms |
30100 KB |
Output is correct |
36 |
Correct |
43 ms |
37736 KB |
Output is correct |
37 |
Correct |
5 ms |
7508 KB |
Output is correct |
38 |
Correct |
5 ms |
7636 KB |
Output is correct |
39 |
Execution timed out |
1094 ms |
10800 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
13140 KB |
Output is correct |
2 |
Correct |
22 ms |
18816 KB |
Output is correct |
3 |
Correct |
21 ms |
20692 KB |
Output is correct |
4 |
Correct |
33 ms |
31372 KB |
Output is correct |
5 |
Correct |
4 ms |
7420 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
26 ms |
24776 KB |
Output is correct |
8 |
Correct |
26 ms |
24256 KB |
Output is correct |
9 |
Correct |
29 ms |
24464 KB |
Output is correct |
10 |
Correct |
27 ms |
25300 KB |
Output is correct |
11 |
Correct |
27 ms |
25756 KB |
Output is correct |
12 |
Correct |
35 ms |
24772 KB |
Output is correct |
13 |
Correct |
45 ms |
33144 KB |
Output is correct |
14 |
Correct |
55 ms |
38272 KB |
Output is correct |
15 |
Correct |
34 ms |
22900 KB |
Output is correct |
16 |
Correct |
46 ms |
37960 KB |
Output is correct |
17 |
Correct |
16 ms |
16340 KB |
Output is correct |
18 |
Correct |
23 ms |
21128 KB |
Output is correct |
19 |
Correct |
5 ms |
7636 KB |
Output is correct |
20 |
Correct |
5 ms |
7636 KB |
Output is correct |
21 |
Correct |
17 ms |
17668 KB |
Output is correct |
22 |
Correct |
18 ms |
18848 KB |
Output is correct |
23 |
Correct |
25 ms |
22896 KB |
Output is correct |
24 |
Correct |
30 ms |
31324 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
4 ms |
7380 KB |
Output is correct |
27 |
Correct |
25 ms |
22092 KB |
Output is correct |
28 |
Correct |
27 ms |
25116 KB |
Output is correct |
29 |
Correct |
28 ms |
25144 KB |
Output is correct |
30 |
Correct |
28 ms |
24584 KB |
Output is correct |
31 |
Correct |
25 ms |
21684 KB |
Output is correct |
32 |
Correct |
31 ms |
21460 KB |
Output is correct |
33 |
Correct |
43 ms |
31572 KB |
Output is correct |
34 |
Correct |
43 ms |
38120 KB |
Output is correct |
35 |
Correct |
29 ms |
30100 KB |
Output is correct |
36 |
Correct |
43 ms |
37736 KB |
Output is correct |
37 |
Correct |
5 ms |
7508 KB |
Output is correct |
38 |
Correct |
5 ms |
7636 KB |
Output is correct |
39 |
Execution timed out |
1094 ms |
10800 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |