This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*************************************
* author: marvinthang *
* created: 08.05.2023 09:11:18 *
*************************************/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define left ___left
#define right ___right
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define MASK(i) (1LL << (i))
#define BIT(x, i) ((x) >> (i) & 1)
#define __builtin_popcount __builtin_popcountll
#define ALL(v) (v).begin(), (v).end()
#define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define REPD(i, n) for (int i = (n); i--; )
#define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; )
#define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
#define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u)
#define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
#include "debug.h"
#else
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define DB(...) 23
#define db(...) 23
#define debug(...) 23
#endif
template <class U, class V> scan_op(pair <U, V>) { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }
// end of template
const int MAX = 2.5e5 + 5;
int N, M, Q;
void init(void) {
cin >> N >> M >> Q;
}
int res[MAX], val[MAX];
vector <pair <int, int>> updateAt[MAX];
vector <pair <int, long long>> queriestAt[MAX];
struct Node {
long long sum_p, sum, cnt, zt, zv;
Node(int v = 0) {
sum_p = cnt = zv = max(v, 0);
sum = v;
zt = max(0, -v);
}
Node operator + (const Node &other) const {
Node res;
res.sum_p = sum_p + other.sum_p;
res.sum = sum + other.sum;
if (cnt >= other.zt) res.cnt = cnt + other.sum;
else res.cnt = other.cnt;
if (zt >= other.zt - sum) {
res.zt = zt;
res.zv = zv + other.sum;
} else {
res.zt = other.zt - sum;
res.zv = sum + other.zv;
}
return res;
}
} st[MAX << 2];
void update(int i, int l, int r, int p, int v) {
if (r - l == 1) {
st[i] = v;
return;
}
int m = l + r >> 1;
if (p < m) update(i << 1, l, m, p, v);
else update(i << 1 | 1, m, r, p, v);
st[i] = st[i << 1] + st[i << 1 | 1];
}
long long getSumP(int i, int l, int r, int p) {
if (l >= p) return 0;
if (r <= p) return st[i].sum_p;
int m = l + r >> 1;
if (p <= m) return getSumP(i << 1, l, m, p);
return st[i << 1].sum_p + getSumP(i << 1 | 1, m, r, p);
}
Node get(int i, int l, int r, int p) {
if (l >= p) return 0;
if (r <= p) return st[i];
int m = l + r >> 1;
if (p <= m) return get(i << 1, l, m, p);
return st[i << 1] + get(i << 1 | 1, m, r, p);
}
int getPos(long long val) {
int i = 1, l = 0, r = Q;
while (true) {
if (r - l == 1) return l;
int m = l + r >> 1;
if (val <= st[i << 1].sum_p) i = i << 1, r = m;
else {
val -= st[i << 1].sum_p;
i = i << 1 | 1;
l = m;
}
}
return -1;
}
void process(void) {
memset(res, -1, sizeof(res));
REP(i, Q) {
long long op, l, r, c, k; cin >> op >> l >> r;
if (op == 1) {
cin >> c >> k;
val[i] = c;
updateAt[l].emplace_back(i, k);
updateAt[r + 1].emplace_back(i, 0);
} else if (op == 2) {
cin >> k;
updateAt[l].emplace_back(i, -k);
updateAt[r + 1].emplace_back(i, 0);
} else queriestAt[l].emplace_back(i, r);
}
FORE(t, 1, N) {
for (auto [i, v]: updateAt[t]) update(1, 0, Q, i, v);
for (auto [i, v]: queriestAt[t]) {
long long p = get(1, 0, Q, i).cnt;
if (p < v) res[i] = 0;
else res[i] = val[getPos(getSumP(1, 0, Q, i) - p + v)];
}
}
REP(i, Q) if (res[i] >= 0) cout << res[i] << '\n';
}
int main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr);
file("C");
init();
process();
cerr << "Time elapsed: " << TIME << " s.\n";
return (0^0);
}
Compilation message (stderr)
foodcourt.cpp: In function 'void update(int, int, int, int, int)':
foodcourt.cpp:86:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
86 | int m = l + r >> 1;
| ~~^~~
foodcourt.cpp: In function 'long long int getSumP(int, int, int, int)':
foodcourt.cpp:95:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
95 | int m = l + r >> 1;
| ~~^~~
foodcourt.cpp: In function 'Node get(int, int, int, int)':
foodcourt.cpp:103:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
103 | int m = l + r >> 1;
| ~~^~~
foodcourt.cpp: In function 'int getPos(long long int)':
foodcourt.cpp:112:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
112 | int m = l + r >> 1;
| ~~^~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:30:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:151:2: note: in expansion of macro 'file'
151 | file("C");
| ^~~~
foodcourt.cpp:30:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:151:2: note: in expansion of macro 'file'
151 | file("C");
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |