This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int ll
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
#ifdef DEBUG
#define debug(args...) _debug(args)
void _debug(const char* format, ...) {
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
}
#else
#define debug(args...)
#endif
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 300005
struct event {
int v, i, t;
};
struct query {
ll v;
int i;
};
int n, m, q;
vector<event> events[MAXN];
vector<query> queries[MAXN];
int grp[MAXN], ans[MAXN];
namespace st {
#define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
ll mn[MAXN * 4], lazy[MAXN * 4];
void propo(int u, int lo, int hi) {
if (lazy[u] == 0 || lo == hi) return;
MLR;
lazy[lc] += lazy[u];
lazy[rc] += lazy[u];
mn[lc] += lazy[u];
mn[rc] += lazy[u];
lazy[u] = 0;
}
void incre(int s, int e, int x, int u = 1, int lo = 1, int hi = q) {
if (lo >= s && hi <= e) {
lazy[u] += x;
mn[u] += x;
return;
}
propo(u, lo, hi);
MLR;
if (s <= mid) {
incre(s, e, x, lc, lo, mid);
}
if (e > mid) {
incre(s, e, x, rc, mid + 1, hi);
}
mn[u] = min(mn[lc], mn[rc]);
}
ll qmn(int s, int e, int u = 1, int lo = 1, int hi = q) {
if (lo >= s && hi <= e) {
return mn[u];
}
propo(u, lo, hi);
MLR;
if (e <= mid) {
return qmn(s, e, lc, lo, mid);
} else if (s > mid) {
return qmn(s, e, rc, mid + 1, hi);
} else {
return min(qmn(s, e, lc, lo, mid), qmn(s, e, rc, mid + 1, hi));
}
}
}
namespace fw {
ll v[MAXN];
void incre(int i, int x) {
for (; i <= q; i += i & -i) v[i] += x;
}
ll qsm(int i) {
ll res = 0;
for (; i > 0; i -= i & -i) res += v[i];
return res;
}
int get(ll x) {
int id = 0;
RREP (k, 25, 0) {
id ^= (1 << k);
if (id > q || v[id] >= x) {
id ^= (1 << k);
} else {
x -= v[id];
}
}
id++;
return id;
}
}
main() {
scanf("%lld%lld%lld", &n, &m, &q);
memset(ans, -1, sizeof ans);
REP (i, 1, q + 1) {
int t; scanf("%lld", &t);
if (t == 1) {
int l, r, c, k; scanf("%lld%lld%lld%lld", &l, &r, &c, &k);
events[l].pb({k, i, 0});
events[r + 1].pb({-k, i, 0});
grp[i] = c;
} else if (t == 2) {
int l, r, k; scanf("%lld%lld%lld", &l, &r, &k);
events[l].pb({-k, i, 1});
events[r + 1].pb({k, i, 1});
} else {
int a; ll b; scanf("%lld%lld", &a, &b);
queries[a].pb({b, i});
}
}
REP (i, 1, n + 1) {
for (event &e : events[i]) {
auto [v, i, t] = e;
st::incre(i, q, v);
if (!t) {
fw::incre(i, v);
}
}
for (query q : queries[i]) {
auto [v, i] = q;
ll rem = st::qmn(i, i) - st::qmn(1, i);
ll tot = fw::qsm(i);
ll rmv = tot - rem;
v += rmv;
if (v > tot) {
ans[i] = 0;
} else {
int id = fw::get(v);
ans[i] = grp[id];
}
}
}
REP (i, 1, q + 1) {
if (ans[i] == -1) continue;
printf("%lld\n", ans[i]);
}
return 0;
}
Compilation message (stderr)
foodcourt.cpp: In function 'void st::propo(ll, ll, ll)':
foodcourt.cpp:58:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | #define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
| ~~~^~~~
foodcourt.cpp:62:3: note: in expansion of macro 'MLR'
62 | MLR;
| ^~~
foodcourt.cpp:58:17: warning: unused variable 'mid' [-Wunused-variable]
58 | #define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
| ^~~
foodcourt.cpp:62:3: note: in expansion of macro 'MLR'
62 | MLR;
| ^~~
foodcourt.cpp: In function 'void st::incre(ll, ll, ll, ll, ll, ll)':
foodcourt.cpp:58:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | #define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
| ~~~^~~~
foodcourt.cpp:76:3: note: in expansion of macro 'MLR'
76 | MLR;
| ^~~
foodcourt.cpp: In function 'll st::qmn(ll, ll, ll, ll, ll)':
foodcourt.cpp:58:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | #define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
| ~~~^~~~
foodcourt.cpp:90:3: note: in expansion of macro 'MLR'
90 | MLR;
| ^~~
foodcourt.cpp: At global scope:
foodcourt.cpp:126:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
126 | main() {
| ^~~~
foodcourt.cpp: In function 'int main()':
foodcourt.cpp:127:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
127 | scanf("%lld%lld%lld", &n, &m, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:130:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
130 | int t; scanf("%lld", &t);
| ~~~~~^~~~~~~~~~~~
foodcourt.cpp:132:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
132 | int l, r, c, k; scanf("%lld%lld%lld%lld", &l, &r, &c, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:137:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
137 | int l, r, k; scanf("%lld%lld%lld", &l, &r, &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:141:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
141 | int a; ll b; scanf("%lld%lld", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
# | 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... |