#include <bits/stdc++.h>
using namespace std;
#define int ll
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<ll, ll>;
struct ura1 {
int n;
vll V, Mi, Lz;
ura1(int N) : n(N), V(N, 0), Mi(4 * N, 0), Lz(4 * N, 0) {}
void prop(int u, int s, int d) {
if(!Lz[u]) return;
Mi[u] += Lz[u];
if(s != d) {
Lz[u << 1] += Lz[u];
Lz[u << 1 | 1] += Lz[u];
}
Lz[u] = 0;
}
void update(int l, int r, int v, int u, int s, int d) {
prop(u, s, d);
if(r < s || d < l) return;
if(l <= s && d <= r) {
Lz[u] += v;
prop(u, s, d);
return;
}
update(l, r, v, u << 1, s, (s + d) >> 1);
update(l, r, v, u << 1 | 1, ((s + d) >> 1) + 1, d);
Mi[u] = min(Mi[u << 1], Mi[u << 1 | 1]);
}
const int INF = 1e9;
int query(int l, int r, int u, int s, int d) {
prop(u, s, d);
if(r < s || d < l) return INF;
if(l <= s && d <= r) return Mi[u];
return min(query(l, r, u << 1, s, (s + d) >> 1),
query(l, r, u << 1 | 1, ((s + d) >> 1) + 1, d));
}
void update(int p, int v) {
///update pe pozitie
update(p, n - 1, v - V[p], 1, 0, n - 1);
V[p] = v;
}
int query(int p) {
if(p == -1) return 0;
return query(p, p, 1, 0, n - 1) - min(query(0, p - 1, 1, 0, n - 1), 0ll);
}
};
struct ura2 {
ll n;
vll S;
ura2(int N) : n(N), S(4 * N) {}
void update(int p, int v, int u, int s, int d) {
if(d < p || p < s) return;
if(s == d) {
S[u] = v;
return;
}
update(p, v, u << 1, s, (s + d) >> 1);
update(p, v, u << 1 | 1, ((s + d) >> 1) + 1, d);
S[u] = S[u << 1] + S[u << 1 | 1];
}
int querys(int l, int r, int u, int s, int d) {
if(d < l || r < s) {
return 0;
}
if(l <= s && d <= r) return S[u];
return querys(l, r, u << 1, s, (s + d) >> 1)
+ querys(l, r, u << 1 | 1, ((s + d) >> 1) + 1, d);
}
int queryp(int nr, int u, int s, int d) {
if(s == d) return s;
if(nr > S[u << 1]) return queryp(nr - S[u << 1], u << 1 | 1, ((s + d) >> 1) + 1, d);
return queryp(nr, u << 1, s, (s + d) >> 1);
}
void update(int p, int v) { ///update pe pozitie
update(p, v, 1, 0, n - 1);
}
int sum(int p) { return querys(0, p, 1, 0, n - 1); }
int query(int nr) { /// va returna pozitia celul a al nr-lea element
return queryp(nr, 1, 0, n - 1);
}
};
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, m, q;
cin >> n >> m >> q;
vi V1, V2, C2;
vector<ii> UpV1, UpV2; /// toggle-uri pe timp
struct query {
int poz, id, ultV1, ultV2;
};
vector<vector<query> > Q(n);
int nr3 = 0;
for (int i = 0; i < q; ++i) {
int tip;
cin >> tip;
if (tip == 1) {
int l, r, c, k;
cin >> l >> r >> c >> k;
--l; --r;
UpV1.push_back({l, V1.size()});
UpV1.push_back({r + 1, V1.size()});
UpV2.push_back({l, V2.size()});
UpV2.push_back({r + 1, V2.size()});
V1.push_back(k);
V2.push_back(k);
C2.push_back(c);
} else if (tip == 2) {
int l, r, k;
cin >> l >> r >> k;
--l; --r;
UpV1.push_back({l, V1.size()});
UpV1.push_back({r + 1, V1.size()});
V1.push_back(-k);
} else {
int a, b;
cin >> a >> b;
--a;
Q[a].push_back({b, nr3, int(V1.size()) - 1, int(V2.size()) - 1});
++nr3;
}
}
sort(UpV1.begin(), UpV1.end());
sort(UpV2.begin(), UpV2.end());
int p1 = 0, p2 = 0;
vi Re(nr3);
ura1 Sol1(V1.size());
vi on1(V1.size(), 0);
ura2 Sol2(V2.size());
vi on2(V2.size(), 0);
for(int i = 0; i < n; ++i) {
while(p1 < UpV1.size() && UpV1[p1].first <= i) {
//toggle it
int v = UpV1[p1].second;
if(!on1[v]) Sol1.update(v, V1[v]);
else Sol1.update(v, 0);
on1[v] ^= 1;
++p1;
}
while(p2 < UpV2.size() && UpV2[p2].first <= i) {
//toggle it
int v = UpV2[p2].second;
if(!on2[v]) Sol2.update(v, V2[v]);
else Sol2.update(v, 0);
on2[v] ^= 1;
++p2;
}
for(auto q : Q[i]) {
ll nrsuf = Sol1.query(q.ultV1), nrtot = Sol2.sum(q.ultV2);
ll b = q.poz + nrtot - nrsuf;
if(b > nrtot) {
Re[q.id] = 0;
} else {
Re[q.id] = C2[Sol2.query(b)];
}
}
}
for(auto it : Re) cout << it << "\n";
return 0;
}
Compilation message
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:155:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
155 | while(p1 < UpV1.size() && UpV1[p1].first <= i) {
| ~~~^~~~~~~~~~~~~
foodcourt.cpp:164:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
164 | while(p2 < UpV2.size() && UpV2[p2].first <= i) {
| ~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
548 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
768 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
548 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
768 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
10208 KB |
Output is correct |
2 |
Correct |
83 ms |
11516 KB |
Output is correct |
3 |
Correct |
70 ms |
10188 KB |
Output is correct |
4 |
Correct |
75 ms |
10348 KB |
Output is correct |
5 |
Correct |
79 ms |
11396 KB |
Output is correct |
6 |
Correct |
89 ms |
11320 KB |
Output is correct |
7 |
Correct |
36 ms |
8076 KB |
Output is correct |
8 |
Correct |
39 ms |
8504 KB |
Output is correct |
9 |
Correct |
76 ms |
10816 KB |
Output is correct |
10 |
Correct |
74 ms |
10920 KB |
Output is correct |
11 |
Correct |
72 ms |
10808 KB |
Output is correct |
12 |
Correct |
75 ms |
10856 KB |
Output is correct |
13 |
Correct |
100 ms |
9880 KB |
Output is correct |
14 |
Correct |
76 ms |
11280 KB |
Output is correct |
15 |
Correct |
93 ms |
13264 KB |
Output is correct |
16 |
Correct |
102 ms |
14012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
369 ms |
38628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
548 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
768 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Correct |
81 ms |
10208 KB |
Output is correct |
22 |
Correct |
83 ms |
11516 KB |
Output is correct |
23 |
Correct |
70 ms |
10188 KB |
Output is correct |
24 |
Correct |
75 ms |
10348 KB |
Output is correct |
25 |
Correct |
79 ms |
11396 KB |
Output is correct |
26 |
Correct |
89 ms |
11320 KB |
Output is correct |
27 |
Correct |
36 ms |
8076 KB |
Output is correct |
28 |
Correct |
39 ms |
8504 KB |
Output is correct |
29 |
Correct |
76 ms |
10816 KB |
Output is correct |
30 |
Correct |
74 ms |
10920 KB |
Output is correct |
31 |
Correct |
72 ms |
10808 KB |
Output is correct |
32 |
Correct |
75 ms |
10856 KB |
Output is correct |
33 |
Correct |
100 ms |
9880 KB |
Output is correct |
34 |
Correct |
76 ms |
11280 KB |
Output is correct |
35 |
Correct |
93 ms |
13264 KB |
Output is correct |
36 |
Correct |
102 ms |
14012 KB |
Output is correct |
37 |
Correct |
74 ms |
9552 KB |
Output is correct |
38 |
Correct |
68 ms |
9340 KB |
Output is correct |
39 |
Correct |
38 ms |
7652 KB |
Output is correct |
40 |
Correct |
42 ms |
8880 KB |
Output is correct |
41 |
Correct |
82 ms |
10764 KB |
Output is correct |
42 |
Correct |
82 ms |
10736 KB |
Output is correct |
43 |
Correct |
88 ms |
10844 KB |
Output is correct |
44 |
Correct |
82 ms |
10832 KB |
Output is correct |
45 |
Correct |
76 ms |
10712 KB |
Output is correct |
46 |
Correct |
75 ms |
10912 KB |
Output is correct |
47 |
Correct |
47 ms |
10400 KB |
Output is correct |
48 |
Correct |
77 ms |
10352 KB |
Output is correct |
49 |
Correct |
54 ms |
8152 KB |
Output is correct |
50 |
Correct |
65 ms |
9828 KB |
Output is correct |
51 |
Correct |
77 ms |
11060 KB |
Output is correct |
52 |
Correct |
78 ms |
11164 KB |
Output is correct |
53 |
Correct |
71 ms |
11380 KB |
Output is correct |
54 |
Correct |
91 ms |
13756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
66 ms |
9360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
548 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
768 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
2 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
548 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
2 ms |
768 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
2 ms |
856 KB |
Output is correct |
21 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |