Submission #1077440

# Submission time Handle Problem Language Result Execution time Memory
1077440 2024-08-27T07:15:44 Z awu Food Court (JOI21_foodcourt) C++17
68 / 100
1000 ms 377260 KB
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")

#define int long long
#define ll long long
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) [](decltype(x) _x) {cerr << #x << " = " << _x << endl; return _x;}(x)
using pii = pair<int, int>;

// const int inf = 1ll << 60;
const int inf = 1 << 30;

template <class T, class _ = decltype(begin(declval<T>()))>
enable_if_t<!is_same_v<T, string>, ostream&> operator<<(ostream& out, T a) {
  string dlm = "";
  out << "{";
  for(auto i : a) {
    out << dlm << i;
    dlm = ", ";
  }
  return out << "}";
}

struct segtree {
  vector<int> t;
  vector<pii> lz;
  segtree(int s) {
    int n = 1;
    while(n < s) n *= 2;
    t.resize(n * 2);
    lz.resize(n * 2);
  }
  void apply(int n, pii upd) {
    lz[n].s += upd.f;
    if(lz[n].s < 0) {
      lz[n].f += lz[n].s;
      lz[n].s = upd.s;
    } else {
      lz[n].s += upd.s;
    }
  }
  void push(int n) {
    t[n] += lz[n].f;
    t[n] = max(t[n], 0ll);
    t[n] += lz[n].s;
    if(n < t.size() / 2) {
      apply(n * 2, lz[n]);
      apply(n * 2 + 1, lz[n]);
    }
    lz[n] = {0, 0};
  }
  void update(int ul, int ur, int v, int n = 1, int tl = 0, int tr = -1) {
    if(tr == -1) tr = t.size() / 2;
    if(ul >= tr || ur <= tl) return;
    if(ul <= tl && ur >= tr) {
      apply(n, {v, 0});
      return;
    }
    push(n);
    int tm = (tl + tr) / 2;
    update(ul, ur, v, n * 2, tl, tm);
    update(ul, ur, v, n * 2 + 1, tm, tr);
    push(n * 2);
    push(n * 2 + 1);
    t[n] = min(t[n * 2], t[n * 2 + 1]);
  }
  int query(int i, int n = 1, int tl = 0, int tr = -1) {
    if(tr == -1) tr = t.size() / 2;
    push(n);
    if(tl + 1 == tr) return t[n];
    int tm = (tl + tr) / 2;
    if(i < tm) return query(i, n * 2, tl, tm);
    return query(i, n * 2 + 1, tm, tr);
  }
};

struct segnode {
  int v;
  signed lc, rc;
  void init();
  void update(int, int, int, int);
  int query(int, int, int, int);
};

const int MAX_Q = 250005;

segnode seg[MAX_Q * 300];
int segsize = 1;

void segnode::init() {
  if(!lc) {
    lc = segsize;
    segsize++;
  }
  if(!rc) {
    rc = segsize;
    segsize++;
  }
}
void segnode::update(int i, int x, int tl, int tr) {
  if(tl + 1 == tr) {
    v = x;
    return;
  }
  signed tm = (tl + tr) / 2;
  if(i < tm) {
    if(!lc) {
      lc = segsize;
      segsize++;
    }
    seg[lc].update(i, x, tl, tm);
    v = seg[lc].v;
    if(rc) v += seg[rc].v;
  } else {
    if(!rc) {
      rc = segsize;
      segsize++;
    }
    seg[rc].update(i, x, tm, tr);
    v = seg[rc].v;
    if(lc) v += seg[lc].v;
  }
}
int segnode::query(int ql, int qr, int tl, int tr) {
  if(ql >= tr || qr <= tl) return 0;
  if(ql <= tl && qr >= tr) return v;
  if(v == 0) return 0;
  int tm = (tl + tr) / 2;
  return (lc ? seg[lc].query(ql, qr, tl, tm) : 0) + (rc ? seg[rc].query(ql, qr, tm, tr) : 0);
}

struct segtree2 {
  int n = 1;
  segtree2(int s) {
    while(n < s) n *= 2;
    segsize = n * 2;
  }
  void update(int l, int r, int v, int time) {
    for(l += n, r += n; l < r; l /= 2, r /= 2) {
      if(l & 1) seg[l++].update(time, v, 0, MAX_Q);
      if(r & 1) seg[--r].update(time, v, 0, MAX_Q);
    }
  }
  int query(int i, int x) { // query earliest time suffix sum of people exceeds x (inclusive)
    vector<signed> nodes;
    for(i += n; i; i /= 2) {
      nodes.push_back(i);
    }
    int tl = 0, tr = MAX_Q;
    while(true) {
      if(tl + 1 == tr) return tl;
      int acc = 0;
      for(auto node : nodes) {
        if(seg[node].rc) acc += seg[seg[node].rc].v;
      }
      vector<signed> newnodes;
      if(acc >= x) {
        for(auto node : nodes) {
          if(seg[node].rc) newnodes.push_back(seg[node].rc);
        }
        tl = (tl + tr) / 2;
      } else {
        x -= acc;
        for(auto node : nodes) {
          if(seg[node].lc) newnodes.push_back(seg[node].lc);
        }
        tr = (tl + tr) / 2;
      }
      swap(nodes, newnodes);
    }
  }
};

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, q; cin >> n >> m >> q;
  segtree st(n);
  segtree2 st2(n);
  vector<int> id(q, -1); // look up c given update time
  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--;
      st.update(l, r, k);
      st2.update(l, r, k, i);
      id[i] = c;
    } else if(t == 2) {
      int l, r, k; cin >> l >> r >> k; l--;
      st.update(l, r, -k);
    } else {
      int a, b; cin >> a >> b; a--; b--;
      int x = st.query(a);
      if(b >= x) cout << 0 << endl;
      else {
        int ri = x - b;
        int lo = st2.query(a, ri);
        cout << id[lo] << "\n" ;
      }
    }
  }
}

Compilation message

foodcourt.cpp: In member function 'void segtree::push(long long int)':
foodcourt.cpp:52:10: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     if(n < t.size() / 2) {
      |        ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1372 KB Output is correct
2 Correct 4 ms 1628 KB Output is correct
3 Correct 4 ms 1508 KB Output is correct
4 Correct 4 ms 1884 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 4 ms 1628 KB Output is correct
8 Correct 4 ms 1628 KB Output is correct
9 Correct 4 ms 1628 KB Output is correct
10 Correct 4 ms 1628 KB Output is correct
11 Correct 4 ms 1628 KB Output is correct
12 Correct 4 ms 1628 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 6 ms 1000 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 4 ms 1768 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 2 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1372 KB Output is correct
2 Correct 4 ms 1628 KB Output is correct
3 Correct 4 ms 1508 KB Output is correct
4 Correct 4 ms 1884 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 4 ms 1628 KB Output is correct
8 Correct 4 ms 1628 KB Output is correct
9 Correct 4 ms 1628 KB Output is correct
10 Correct 4 ms 1628 KB Output is correct
11 Correct 4 ms 1628 KB Output is correct
12 Correct 4 ms 1628 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 6 ms 1000 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 4 ms 1768 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 2 ms 1628 KB Output is correct
21 Correct 4 ms 1624 KB Output is correct
22 Correct 4 ms 1624 KB Output is correct
23 Correct 4 ms 1628 KB Output is correct
24 Correct 4 ms 1884 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 1628 KB Output is correct
28 Correct 4 ms 1628 KB Output is correct
29 Correct 5 ms 1624 KB Output is correct
30 Correct 4 ms 1628 KB Output is correct
31 Correct 4 ms 1732 KB Output is correct
32 Correct 3 ms 1628 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 3 ms 1116 KB Output is correct
36 Correct 3 ms 1368 KB Output is correct
37 Correct 2 ms 1116 KB Output is correct
38 Correct 3 ms 1628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 21980 KB Output is correct
2 Correct 91 ms 29520 KB Output is correct
3 Correct 92 ms 27216 KB Output is correct
4 Correct 100 ms 27220 KB Output is correct
5 Correct 92 ms 36756 KB Output is correct
6 Correct 92 ms 36828 KB Output is correct
7 Correct 30 ms 2640 KB Output is correct
8 Correct 36 ms 2820 KB Output is correct
9 Correct 78 ms 23896 KB Output is correct
10 Correct 79 ms 23888 KB Output is correct
11 Correct 81 ms 23892 KB Output is correct
12 Correct 82 ms 24004 KB Output is correct
13 Correct 86 ms 27472 KB Output is correct
14 Correct 103 ms 31428 KB Output is correct
15 Correct 93 ms 42788 KB Output is correct
16 Correct 96 ms 44628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 804 ms 260944 KB Output is correct
2 Correct 610 ms 208000 KB Output is correct
3 Correct 883 ms 287364 KB Output is correct
4 Correct 828 ms 294484 KB Output is correct
5 Correct 803 ms 289104 KB Output is correct
6 Execution timed out 1093 ms 377260 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1372 KB Output is correct
2 Correct 4 ms 1628 KB Output is correct
3 Correct 4 ms 1508 KB Output is correct
4 Correct 4 ms 1884 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 4 ms 1628 KB Output is correct
8 Correct 4 ms 1628 KB Output is correct
9 Correct 4 ms 1628 KB Output is correct
10 Correct 4 ms 1628 KB Output is correct
11 Correct 4 ms 1628 KB Output is correct
12 Correct 4 ms 1628 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 6 ms 1000 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 4 ms 1768 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 2 ms 1628 KB Output is correct
21 Correct 93 ms 21980 KB Output is correct
22 Correct 91 ms 29520 KB Output is correct
23 Correct 92 ms 27216 KB Output is correct
24 Correct 100 ms 27220 KB Output is correct
25 Correct 92 ms 36756 KB Output is correct
26 Correct 92 ms 36828 KB Output is correct
27 Correct 30 ms 2640 KB Output is correct
28 Correct 36 ms 2820 KB Output is correct
29 Correct 78 ms 23896 KB Output is correct
30 Correct 79 ms 23888 KB Output is correct
31 Correct 81 ms 23892 KB Output is correct
32 Correct 82 ms 24004 KB Output is correct
33 Correct 86 ms 27472 KB Output is correct
34 Correct 103 ms 31428 KB Output is correct
35 Correct 93 ms 42788 KB Output is correct
36 Correct 96 ms 44628 KB Output is correct
37 Correct 155 ms 55612 KB Output is correct
38 Correct 175 ms 69456 KB Output is correct
39 Correct 22 ms 2392 KB Output is correct
40 Correct 28 ms 2908 KB Output is correct
41 Correct 193 ms 64516 KB Output is correct
42 Correct 185 ms 67920 KB Output is correct
43 Correct 179 ms 68996 KB Output is correct
44 Correct 183 ms 66812 KB Output is correct
45 Correct 183 ms 68436 KB Output is correct
46 Correct 181 ms 69204 KB Output is correct
47 Correct 70 ms 16720 KB Output is correct
48 Correct 141 ms 42576 KB Output is correct
49 Correct 128 ms 49744 KB Output is correct
50 Correct 152 ms 62036 KB Output is correct
51 Correct 184 ms 72648 KB Output is correct
52 Correct 178 ms 72272 KB Output is correct
53 Correct 81 ms 35888 KB Output is correct
54 Correct 99 ms 44624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 78524 KB Output is correct
2 Correct 243 ms 84308 KB Output is correct
3 Correct 242 ms 88264 KB Output is correct
4 Correct 178 ms 63056 KB Output is correct
5 Correct 228 ms 75860 KB Output is correct
6 Correct 246 ms 87684 KB Output is correct
7 Correct 37 ms 3244 KB Output is correct
8 Correct 42 ms 3664 KB Output is correct
9 Correct 95 ms 20816 KB Output is correct
10 Correct 120 ms 40012 KB Output is correct
11 Correct 183 ms 57192 KB Output is correct
12 Correct 182 ms 57156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1372 KB Output is correct
2 Correct 4 ms 1628 KB Output is correct
3 Correct 4 ms 1508 KB Output is correct
4 Correct 4 ms 1884 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 4 ms 1628 KB Output is correct
8 Correct 4 ms 1628 KB Output is correct
9 Correct 4 ms 1628 KB Output is correct
10 Correct 4 ms 1628 KB Output is correct
11 Correct 4 ms 1628 KB Output is correct
12 Correct 4 ms 1628 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 6 ms 1000 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 4 ms 1768 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 2 ms 1628 KB Output is correct
21 Correct 4 ms 1624 KB Output is correct
22 Correct 4 ms 1624 KB Output is correct
23 Correct 4 ms 1628 KB Output is correct
24 Correct 4 ms 1884 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 1628 KB Output is correct
28 Correct 4 ms 1628 KB Output is correct
29 Correct 5 ms 1624 KB Output is correct
30 Correct 4 ms 1628 KB Output is correct
31 Correct 4 ms 1732 KB Output is correct
32 Correct 3 ms 1628 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 3 ms 1116 KB Output is correct
36 Correct 3 ms 1368 KB Output is correct
37 Correct 2 ms 1116 KB Output is correct
38 Correct 3 ms 1628 KB Output is correct
39 Correct 93 ms 21980 KB Output is correct
40 Correct 91 ms 29520 KB Output is correct
41 Correct 92 ms 27216 KB Output is correct
42 Correct 100 ms 27220 KB Output is correct
43 Correct 92 ms 36756 KB Output is correct
44 Correct 92 ms 36828 KB Output is correct
45 Correct 30 ms 2640 KB Output is correct
46 Correct 36 ms 2820 KB Output is correct
47 Correct 78 ms 23896 KB Output is correct
48 Correct 79 ms 23888 KB Output is correct
49 Correct 81 ms 23892 KB Output is correct
50 Correct 82 ms 24004 KB Output is correct
51 Correct 86 ms 27472 KB Output is correct
52 Correct 103 ms 31428 KB Output is correct
53 Correct 93 ms 42788 KB Output is correct
54 Correct 96 ms 44628 KB Output is correct
55 Correct 155 ms 55612 KB Output is correct
56 Correct 175 ms 69456 KB Output is correct
57 Correct 22 ms 2392 KB Output is correct
58 Correct 28 ms 2908 KB Output is correct
59 Correct 193 ms 64516 KB Output is correct
60 Correct 185 ms 67920 KB Output is correct
61 Correct 179 ms 68996 KB Output is correct
62 Correct 183 ms 66812 KB Output is correct
63 Correct 183 ms 68436 KB Output is correct
64 Correct 181 ms 69204 KB Output is correct
65 Correct 70 ms 16720 KB Output is correct
66 Correct 141 ms 42576 KB Output is correct
67 Correct 128 ms 49744 KB Output is correct
68 Correct 152 ms 62036 KB Output is correct
69 Correct 184 ms 72648 KB Output is correct
70 Correct 178 ms 72272 KB Output is correct
71 Correct 81 ms 35888 KB Output is correct
72 Correct 99 ms 44624 KB Output is correct
73 Correct 226 ms 78524 KB Output is correct
74 Correct 243 ms 84308 KB Output is correct
75 Correct 242 ms 88264 KB Output is correct
76 Correct 178 ms 63056 KB Output is correct
77 Correct 228 ms 75860 KB Output is correct
78 Correct 246 ms 87684 KB Output is correct
79 Correct 37 ms 3244 KB Output is correct
80 Correct 42 ms 3664 KB Output is correct
81 Correct 95 ms 20816 KB Output is correct
82 Correct 120 ms 40012 KB Output is correct
83 Correct 183 ms 57192 KB Output is correct
84 Correct 182 ms 57156 KB Output is correct
85 Correct 211 ms 56152 KB Output is correct
86 Correct 181 ms 63820 KB Output is correct
87 Correct 199 ms 76368 KB Output is correct
88 Correct 223 ms 87888 KB Output is correct
89 Correct 109 ms 43876 KB Output is correct
90 Correct 197 ms 68380 KB Output is correct
91 Correct 155 ms 53964 KB Output is correct
92 Correct 136 ms 51676 KB Output is correct
93 Correct 192 ms 69460 KB Output is correct
94 Correct 192 ms 67668 KB Output is correct
95 Correct 181 ms 66420 KB Output is correct
96 Correct 192 ms 69712 KB Output is correct
97 Correct 180 ms 69972 KB Output is correct
98 Correct 154 ms 56916 KB Output is correct
99 Correct 74 ms 17488 KB Output is correct
100 Correct 124 ms 35920 KB Output is correct
101 Correct 145 ms 42988 KB Output is correct
102 Correct 116 ms 49748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1372 KB Output is correct
2 Correct 4 ms 1628 KB Output is correct
3 Correct 4 ms 1508 KB Output is correct
4 Correct 4 ms 1884 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 4 ms 1628 KB Output is correct
8 Correct 4 ms 1628 KB Output is correct
9 Correct 4 ms 1628 KB Output is correct
10 Correct 4 ms 1628 KB Output is correct
11 Correct 4 ms 1628 KB Output is correct
12 Correct 4 ms 1628 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 6 ms 1000 KB Output is correct
17 Correct 3 ms 1372 KB Output is correct
18 Correct 4 ms 1768 KB Output is correct
19 Correct 2 ms 1372 KB Output is correct
20 Correct 2 ms 1628 KB Output is correct
21 Correct 4 ms 1624 KB Output is correct
22 Correct 4 ms 1624 KB Output is correct
23 Correct 4 ms 1628 KB Output is correct
24 Correct 4 ms 1884 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 4 ms 1628 KB Output is correct
28 Correct 4 ms 1628 KB Output is correct
29 Correct 5 ms 1624 KB Output is correct
30 Correct 4 ms 1628 KB Output is correct
31 Correct 4 ms 1732 KB Output is correct
32 Correct 3 ms 1628 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 3 ms 1116 KB Output is correct
36 Correct 3 ms 1368 KB Output is correct
37 Correct 2 ms 1116 KB Output is correct
38 Correct 3 ms 1628 KB Output is correct
39 Correct 93 ms 21980 KB Output is correct
40 Correct 91 ms 29520 KB Output is correct
41 Correct 92 ms 27216 KB Output is correct
42 Correct 100 ms 27220 KB Output is correct
43 Correct 92 ms 36756 KB Output is correct
44 Correct 92 ms 36828 KB Output is correct
45 Correct 30 ms 2640 KB Output is correct
46 Correct 36 ms 2820 KB Output is correct
47 Correct 78 ms 23896 KB Output is correct
48 Correct 79 ms 23888 KB Output is correct
49 Correct 81 ms 23892 KB Output is correct
50 Correct 82 ms 24004 KB Output is correct
51 Correct 86 ms 27472 KB Output is correct
52 Correct 103 ms 31428 KB Output is correct
53 Correct 93 ms 42788 KB Output is correct
54 Correct 96 ms 44628 KB Output is correct
55 Correct 804 ms 260944 KB Output is correct
56 Correct 610 ms 208000 KB Output is correct
57 Correct 883 ms 287364 KB Output is correct
58 Correct 828 ms 294484 KB Output is correct
59 Correct 803 ms 289104 KB Output is correct
60 Execution timed out 1093 ms 377260 KB Time limit exceeded
61 Halted 0 ms 0 KB -