#pragma GCC optimize("unroll-loops")
#pragma gcc optimize("Ofast")
#pragma GCC optimization("Ofast")
#pragma optimize(Ofast)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
#define str string
#define fs first
#define ss second
#define all(a) a.begin(), a.end()
#define print(a) \
for (auto x : a) \
cout << x << ' '; \
cout << endl;
void __print(signed x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const str &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const array<int, 2> &x)
{
cerr << '{';
__print(x[0]);
cerr << ',';
__print(x[1]);
cerr << '}';
}
template <typename T, typename V>
void __print(const pair<T, V> &x)
{
cerr << '{';
__print(x.fs);
cerr << ',';
__print(x.ss);
cerr << '}';
}
template <typename T>
void __print(const T &x)
{
int f = 0;
cerr << '{';
for (auto &y : x)
cerr << (f++ ? "," : ""), __print(y);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#ifdef ONLINE_JUDGE
#define debug(x...) 42
#endif
const int mod = 1e9 + 7;
struct SegTree
{
int size = 1;
vector<int> sum, adds;
SegTree(int n)
{
while (size < n)
size <<= 1;
sum.resize(size << 1);
adds.resize(size << 1);
}
void add(int l, int r, int v, int x, int lx, int rx)
{
if (l <= lx and rx <= r)
{
sum[x] += max(v, -adds[x]) * (rx - lx);
adds[x] += v;
adds[x] = max(adds[x], 0ll);
return;
}
if (r <= lx or rx <= l)
return;
int m = (lx + rx) >> 1;
add(l, r, v, (x << 1) + 1, lx, m);
add(l, r, v, (x << 1) + 2, m, rx);
sum[x] = sum[(x << 1) + 1] + sum[(x << 1) + 2] + adds[x] * (rx - lx);
}
inline void add(int l, int r, int v)
{
add(l, r, v, 0, 0, size);
}
int get(int l, int r, int x, int lx, int rx)
{
if (l <= lx and rx <= r)
return sum[x];
if (r <= lx or rx <= l)
return 0;
int m = (lx + rx) >> 1;
int ans = get(l, r, (x << 1) + 1, lx, m) + get(l, r, (x << 1) + 2, m, rx) + adds[x] * (min(r, rx) - max(l, lx));
return ans;
}
inline int get(int l, int r)
{
return get(l, r, 0, 0, size);
}
};
void solve()
{
int n, m, q;
cin >> n >> m >> q;
if (m == 1)
{
SegTree s(n);
for (int i = 0; i < q; i++)
{
int t;
cin >> t;
if (t == 1)
{
int l, r, c, k;
cin >> l >> r >> c >> k;
l--;
s.add(l, r, k);
}
else if (t == 2)
{
int l, r, k;
cin >> l >> r >> k;
l--;
s.add(l, r, -k);
}
else
{
int a, b;
cin >> a >> b;
int x = s.get(a - 1, a);
if(x >= b)
cout << 1;
else
cout << 0;
if(i < q - 1)
cout << endl;
}
}
}
else{
vector<queue<array<int, 2>>> p(n);
for(int i = 0; i < q; i ++){
int t;
cin >> t;
if(t == 1){
int l, r, c, k;
cin >> l >> r >> c >> k;
for(int j = l - 1; j < r; j ++)
p[j].push({c, k});
}
else if(t == 2){
int l, r, k;
cin >> l >> r >> k;
for(int j = l - 1; j < r; j ++){
int x = k;
while(!p[j].empty() and p[j].front()[1] <= x)
x -= p[j].front()[1], p[j].pop();
if(!p[j].empty())
p[j].front()[1] -= x;
}
}
else{
int a, b;
cin >> a >> b;
int ans = 0;
a --;
queue<array<int, 2>> new_q = p[a];
while(!new_q.empty() and b > 0){
array<int, 2> x = new_q.front();
if(x[1] < b)
b -= x[1], new_q.pop();
else{
b -= x[1];
}
}
if(b > 0)
cout << 0;
else
cout << new_q.front()[0];
if(i < q - 1)
cout << endl;
}
}
}
}
signed main()
{
fastio;
int t = 1;
// cin >> t;
while (t--)
solve();
}
Compilation message
foodcourt.cpp:2: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
2 | #pragma gcc optimize("Ofast")
|
foodcourt.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization("Ofast")
|
foodcourt.cpp:4: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
4 | #pragma optimize(Ofast)
|
foodcourt.cpp: In function 'void solve()':
foodcourt.cpp:195:21: warning: unused variable 'ans' [-Wunused-variable]
195 | int ans = 0;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1880 KB |
Output is correct |
2 |
Correct |
5 ms |
2652 KB |
Output is correct |
3 |
Correct |
7 ms |
9052 KB |
Output is correct |
4 |
Correct |
12 ms |
12636 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
16 ms |
14420 KB |
Output is correct |
8 |
Correct |
12 ms |
9816 KB |
Output is correct |
9 |
Correct |
7 ms |
2652 KB |
Output is correct |
10 |
Correct |
10 ms |
9392 KB |
Output is correct |
11 |
Correct |
9 ms |
6492 KB |
Output is correct |
12 |
Correct |
9 ms |
2676 KB |
Output is correct |
13 |
Correct |
7 ms |
2396 KB |
Output is correct |
14 |
Correct |
10 ms |
3676 KB |
Output is correct |
15 |
Correct |
8 ms |
4700 KB |
Output is correct |
16 |
Correct |
11 ms |
3876 KB |
Output is correct |
17 |
Correct |
4 ms |
1628 KB |
Output is correct |
18 |
Correct |
6 ms |
2136 KB |
Output is correct |
19 |
Correct |
1 ms |
1372 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1880 KB |
Output is correct |
2 |
Correct |
5 ms |
2652 KB |
Output is correct |
3 |
Correct |
7 ms |
9052 KB |
Output is correct |
4 |
Correct |
12 ms |
12636 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
16 ms |
14420 KB |
Output is correct |
8 |
Correct |
12 ms |
9816 KB |
Output is correct |
9 |
Correct |
7 ms |
2652 KB |
Output is correct |
10 |
Correct |
10 ms |
9392 KB |
Output is correct |
11 |
Correct |
9 ms |
6492 KB |
Output is correct |
12 |
Correct |
9 ms |
2676 KB |
Output is correct |
13 |
Correct |
7 ms |
2396 KB |
Output is correct |
14 |
Correct |
10 ms |
3676 KB |
Output is correct |
15 |
Correct |
8 ms |
4700 KB |
Output is correct |
16 |
Correct |
11 ms |
3876 KB |
Output is correct |
17 |
Correct |
4 ms |
1628 KB |
Output is correct |
18 |
Correct |
6 ms |
2136 KB |
Output is correct |
19 |
Correct |
1 ms |
1372 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
21 |
Correct |
5 ms |
2396 KB |
Output is correct |
22 |
Correct |
6 ms |
2904 KB |
Output is correct |
23 |
Correct |
8 ms |
8540 KB |
Output is correct |
24 |
Correct |
12 ms |
12860 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
15 ms |
13656 KB |
Output is correct |
28 |
Correct |
13 ms |
10588 KB |
Output is correct |
29 |
Correct |
9 ms |
4444 KB |
Output is correct |
30 |
Correct |
12 ms |
8916 KB |
Output is correct |
31 |
Correct |
10 ms |
6492 KB |
Output is correct |
32 |
Correct |
7 ms |
2396 KB |
Output is correct |
33 |
Correct |
7 ms |
2472 KB |
Output is correct |
34 |
Correct |
11 ms |
4964 KB |
Output is correct |
35 |
Correct |
8 ms |
2908 KB |
Output is correct |
36 |
Correct |
11 ms |
3672 KB |
Output is correct |
37 |
Correct |
1 ms |
1372 KB |
Output is correct |
38 |
Correct |
2 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
672 ms |
45572 KB |
Output is correct |
2 |
Correct |
534 ms |
45652 KB |
Output is correct |
3 |
Correct |
678 ms |
45396 KB |
Output is correct |
4 |
Correct |
667 ms |
45292 KB |
Output is correct |
5 |
Correct |
525 ms |
45232 KB |
Output is correct |
6 |
Correct |
539 ms |
45436 KB |
Output is correct |
7 |
Correct |
14 ms |
1116 KB |
Output is correct |
8 |
Correct |
15 ms |
1116 KB |
Output is correct |
9 |
Execution timed out |
1060 ms |
45472 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
135 ms |
8788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1880 KB |
Output is correct |
2 |
Correct |
5 ms |
2652 KB |
Output is correct |
3 |
Correct |
7 ms |
9052 KB |
Output is correct |
4 |
Correct |
12 ms |
12636 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
16 ms |
14420 KB |
Output is correct |
8 |
Correct |
12 ms |
9816 KB |
Output is correct |
9 |
Correct |
7 ms |
2652 KB |
Output is correct |
10 |
Correct |
10 ms |
9392 KB |
Output is correct |
11 |
Correct |
9 ms |
6492 KB |
Output is correct |
12 |
Correct |
9 ms |
2676 KB |
Output is correct |
13 |
Correct |
7 ms |
2396 KB |
Output is correct |
14 |
Correct |
10 ms |
3676 KB |
Output is correct |
15 |
Correct |
8 ms |
4700 KB |
Output is correct |
16 |
Correct |
11 ms |
3876 KB |
Output is correct |
17 |
Correct |
4 ms |
1628 KB |
Output is correct |
18 |
Correct |
6 ms |
2136 KB |
Output is correct |
19 |
Correct |
1 ms |
1372 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
21 |
Correct |
672 ms |
45572 KB |
Output is correct |
22 |
Correct |
534 ms |
45652 KB |
Output is correct |
23 |
Correct |
678 ms |
45396 KB |
Output is correct |
24 |
Correct |
667 ms |
45292 KB |
Output is correct |
25 |
Correct |
525 ms |
45232 KB |
Output is correct |
26 |
Correct |
539 ms |
45436 KB |
Output is correct |
27 |
Correct |
14 ms |
1116 KB |
Output is correct |
28 |
Correct |
15 ms |
1116 KB |
Output is correct |
29 |
Execution timed out |
1060 ms |
45472 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
542 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1880 KB |
Output is correct |
2 |
Correct |
5 ms |
2652 KB |
Output is correct |
3 |
Correct |
7 ms |
9052 KB |
Output is correct |
4 |
Correct |
12 ms |
12636 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
16 ms |
14420 KB |
Output is correct |
8 |
Correct |
12 ms |
9816 KB |
Output is correct |
9 |
Correct |
7 ms |
2652 KB |
Output is correct |
10 |
Correct |
10 ms |
9392 KB |
Output is correct |
11 |
Correct |
9 ms |
6492 KB |
Output is correct |
12 |
Correct |
9 ms |
2676 KB |
Output is correct |
13 |
Correct |
7 ms |
2396 KB |
Output is correct |
14 |
Correct |
10 ms |
3676 KB |
Output is correct |
15 |
Correct |
8 ms |
4700 KB |
Output is correct |
16 |
Correct |
11 ms |
3876 KB |
Output is correct |
17 |
Correct |
4 ms |
1628 KB |
Output is correct |
18 |
Correct |
6 ms |
2136 KB |
Output is correct |
19 |
Correct |
1 ms |
1372 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
21 |
Correct |
5 ms |
2396 KB |
Output is correct |
22 |
Correct |
6 ms |
2904 KB |
Output is correct |
23 |
Correct |
8 ms |
8540 KB |
Output is correct |
24 |
Correct |
12 ms |
12860 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
15 ms |
13656 KB |
Output is correct |
28 |
Correct |
13 ms |
10588 KB |
Output is correct |
29 |
Correct |
9 ms |
4444 KB |
Output is correct |
30 |
Correct |
12 ms |
8916 KB |
Output is correct |
31 |
Correct |
10 ms |
6492 KB |
Output is correct |
32 |
Correct |
7 ms |
2396 KB |
Output is correct |
33 |
Correct |
7 ms |
2472 KB |
Output is correct |
34 |
Correct |
11 ms |
4964 KB |
Output is correct |
35 |
Correct |
8 ms |
2908 KB |
Output is correct |
36 |
Correct |
11 ms |
3672 KB |
Output is correct |
37 |
Correct |
1 ms |
1372 KB |
Output is correct |
38 |
Correct |
2 ms |
1628 KB |
Output is correct |
39 |
Correct |
672 ms |
45572 KB |
Output is correct |
40 |
Correct |
534 ms |
45652 KB |
Output is correct |
41 |
Correct |
678 ms |
45396 KB |
Output is correct |
42 |
Correct |
667 ms |
45292 KB |
Output is correct |
43 |
Correct |
525 ms |
45232 KB |
Output is correct |
44 |
Correct |
539 ms |
45436 KB |
Output is correct |
45 |
Correct |
14 ms |
1116 KB |
Output is correct |
46 |
Correct |
15 ms |
1116 KB |
Output is correct |
47 |
Execution timed out |
1060 ms |
45472 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1880 KB |
Output is correct |
2 |
Correct |
5 ms |
2652 KB |
Output is correct |
3 |
Correct |
7 ms |
9052 KB |
Output is correct |
4 |
Correct |
12 ms |
12636 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
16 ms |
14420 KB |
Output is correct |
8 |
Correct |
12 ms |
9816 KB |
Output is correct |
9 |
Correct |
7 ms |
2652 KB |
Output is correct |
10 |
Correct |
10 ms |
9392 KB |
Output is correct |
11 |
Correct |
9 ms |
6492 KB |
Output is correct |
12 |
Correct |
9 ms |
2676 KB |
Output is correct |
13 |
Correct |
7 ms |
2396 KB |
Output is correct |
14 |
Correct |
10 ms |
3676 KB |
Output is correct |
15 |
Correct |
8 ms |
4700 KB |
Output is correct |
16 |
Correct |
11 ms |
3876 KB |
Output is correct |
17 |
Correct |
4 ms |
1628 KB |
Output is correct |
18 |
Correct |
6 ms |
2136 KB |
Output is correct |
19 |
Correct |
1 ms |
1372 KB |
Output is correct |
20 |
Correct |
1 ms |
1628 KB |
Output is correct |
21 |
Correct |
5 ms |
2396 KB |
Output is correct |
22 |
Correct |
6 ms |
2904 KB |
Output is correct |
23 |
Correct |
8 ms |
8540 KB |
Output is correct |
24 |
Correct |
12 ms |
12860 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
15 ms |
13656 KB |
Output is correct |
28 |
Correct |
13 ms |
10588 KB |
Output is correct |
29 |
Correct |
9 ms |
4444 KB |
Output is correct |
30 |
Correct |
12 ms |
8916 KB |
Output is correct |
31 |
Correct |
10 ms |
6492 KB |
Output is correct |
32 |
Correct |
7 ms |
2396 KB |
Output is correct |
33 |
Correct |
7 ms |
2472 KB |
Output is correct |
34 |
Correct |
11 ms |
4964 KB |
Output is correct |
35 |
Correct |
8 ms |
2908 KB |
Output is correct |
36 |
Correct |
11 ms |
3672 KB |
Output is correct |
37 |
Correct |
1 ms |
1372 KB |
Output is correct |
38 |
Correct |
2 ms |
1628 KB |
Output is correct |
39 |
Correct |
672 ms |
45572 KB |
Output is correct |
40 |
Correct |
534 ms |
45652 KB |
Output is correct |
41 |
Correct |
678 ms |
45396 KB |
Output is correct |
42 |
Correct |
667 ms |
45292 KB |
Output is correct |
43 |
Correct |
525 ms |
45232 KB |
Output is correct |
44 |
Correct |
539 ms |
45436 KB |
Output is correct |
45 |
Correct |
14 ms |
1116 KB |
Output is correct |
46 |
Correct |
15 ms |
1116 KB |
Output is correct |
47 |
Execution timed out |
1060 ms |
45472 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |