QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#67267#5098. 第一代图灵机yukino_yukinoshita30 740ms32656kbC++144.4kb2022-12-10 11:17:472022-12-10 11:18:13

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-10 11:18:13]
  • Judged
  • Verdict: 30
  • Time: 740ms
  • Memory: 32656kb
  • [2022-12-10 11:17:47]
  • Submitted

answer

#include <bits/stdc++.h>
#define FOR(i,j,k) for(int i=j; i<=k; ++i)
#define ROF(i,j,k) for(int i=j; i>=k; --i)
inline int read (void) {
  int x = 0, f = 1, ch = getchar();
  while(!isdigit(ch)) { if(ch == '-') f = -f; ch = getchar(); }
  while(isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); }
  return x * f;
}
using ll = long long;
const int maxn = 200005;
const int maxm = 524288;
namespace sgt {
  #define mid (l + r >> 1)
  ll t[maxm];
  void modify (int l, int r, int q, ll c, int k=1) {
    if(l == r) { t[k] = c; return ; }
    if(q <= mid) modify (l, mid, q, c, k<<1);
    else modify (mid+1, r, q, c, k<<1|1);
    t[k] = std::max(t[k<<1], t[k<<1|1]);
  }
  ll query (int l, int r, int ql, int qr, int k=1) {
    if(ql <= l && r <= qr) return t[k];
    if(ql <= mid)
      if(mid < qr) return std::max(query (l, mid, ql, qr, k<<1), query (mid+1, r, ql, qr, k<<1|1));
      else return query (l, mid, ql, qr, k<<1);
    else return query (mid+1, r, ql, qr, k<<1|1);
  }
  #undef mid
}
int c[maxn], nxt[maxn], lp[maxn];
ll a[maxn];
std::set <int> s[maxn];
struct Node {
  std::priority_queue <int, std::vector <int>, std::greater <int> > q, q1;
  inline void push (int x) { q.push(x); }
  inline void pop (int x) { q1.push(x); }
  inline int top (void) {
    while(!q1.empty() && q1.top() == q.top())
      q.pop(), q1.pop();
    return q.top();
  }
  inline void clear (void) {
    while(!q.empty()) q.pop();
    while(!q1.empty()) q1.pop();
  }
} node;
int main (void) {
  int n = read(), m = read(), q = read();
  if(n <= 5000) {
    FOR(i,1,n) a[i] = a[i-1] + read();
    FOR(i,1,n) c[i] = read();
    FOR(i,1,m) s[i].insert (n+1);
    ROF(i,n,1) {
      nxt[i] = *s[c[i]].begin();
      s[c[i]].insert (i);
    }
    FOR(i,1,m) s[i].insert (0);
    while(q--) {
      int opt = read(), l = read(), r = read();
      if(opt == 1) {
        ll ans = 0;
        for(int L=l, R=l; R<=r; ++R) {
          node.push(nxt[R]);
          while(node.top() == R)
            node.pop(nxt[L ++]);
          ans = std::max(a[R] - a[L-1], ans);
        } node.clear ();
        printf("%lld\n", ans);
      } else {
        nxt[*prev(s[c[l]].lower_bound (l))] = *s[c[l]].upper_bound (l);
        s[c[l]].erase (l);
        s[c[l] = r].insert (l);
        nxt[*prev(s[c[l]].lower_bound (l))] = l;
        nxt[l] = *s[c[l]].upper_bound (l);
      }
    }
  } else if(m <= 10) {
    FOR(i,1,n) a[i] = a[i-1] + read();
    FOR(i,1,n) c[i] = read();
    FOR(i,1,m) s[i].insert (n+1);
    ROF(i,n,1) {
      nxt[i] = *s[c[i]].begin();
      s[c[i]].insert (i);
    }
    FOR(i,1,m) s[i].insert (0);
    for(int L=1, R=1; R<=n; ++R) {
      node.push(nxt[R]);
      while(node.top() == R)
        node.pop(nxt[L ++]);
      lp[R] = L;
      sgt::modify (1, n, R, a[R] - a[L-1]);
    } node.clear ();
    while(q--) {
      int opt = read(), l = read(), r = read();
      if(opt == 1) {
        if(lp[r] <= l) printf("%lld\n", a[r] - a[l-1]);
        else {
          int L = std::upper_bound (lp+1, lp+n+1, l) - lp;
          printf("%lld\n", std::max(a[L-1] - a[l-1], sgt::query (1, n, L, r)));
        }
      } else {
        nxt[*prev(s[c[l]].lower_bound (l))] = *s[c[l]].upper_bound (l);
        s[c[l]].erase (l);
        s[c[l] = r].insert (l);
        nxt[*prev(s[c[l]].lower_bound (l))] = l;
        nxt[l] = *s[c[l]].upper_bound (l);
        for(int L=std::max(1, l-20), R=std::max(1, l-20); R<=l; ++R) {
          node.push(nxt[R]);
          while(node.top() == R)
            node.pop(nxt[L ++]);
          if(R >= l - 10) lp[R] = L;
          sgt::modify (1, n, R, a[R] - a[L-1]);
        } node.clear ();
      }
    }
  } else {
    FOR(i,1,n) a[i] = a[i-1] + read();
    FOR(i,1,n) c[i] = read();
    FOR(i,1,m) s[i].insert (n+1);
    ROF(i,n,1) {
      nxt[i] = *s[c[i]].begin();
      s[c[i]].insert (i);
    }
    FOR(i,1,m) s[i].insert (0);
    for(int L=1, R=1; R<=n; ++R) {
      node.push(nxt[R]);
      while(node.top() == R)
        node.pop(nxt[L ++]);
      lp[R] = L;
      sgt::modify (1, n, R, a[R] - a[L-1]);
    } node.clear ();
    while(q--) {
      int opt = read(), l = read(), r = read();
      if(lp[r] <= l) printf("%lld\n", a[r] - a[l-1]);
      else {
        int L = std::upper_bound (lp+1, lp+n+1, l) - lp;
        printf("%lld\n", std::max(a[L-1] - a[l-1], sgt::query (1, n, L, r)));
      }
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 718ms
memory: 13212kb

input:

5000 200 5000
2315 3433 1793 4621 4627 4561 289 4399 3822 2392 392 4581 2643 2441 4572 4649 2981 3094 4206 2057 761 2516 2849 3509 3033 658 4965 3316 3269 4284 4961 753 1187 2515 1377 1725 4743 4761 3823 3464 4859 989 2401 953 875 1481 2181 103 2067 2625 3296 4721 61 3843 1607 997 4385 1284 4299 441...

output:

118571
90725
79596
95154
95154
94493
72411
100567
100567
100567
100567
90725
100567
100567
90725
118571
94493
95154
58191
118571
100567
100567
100567
39374
89208
118571
99923
100567
100567
95724
87252
100567
118571
100567
100567
100567
100567
100567
100567
26617
100567
99923
100567
118571
100567
100...

result:

ok 3799 lines

Test #2:

score: 0
Accepted
time: 740ms
memory: 13316kb

input:

5000 1000 5000
451 521 3465 4281 3422 1186 2547 3341 2060 1467 717 2115 2513 2471 1399 1812 3070 2173 521 1621 2801 4020 4493 138 4162 97 1179 171 4011 3340 2393 689 1830 3981 2352 3352 3561 2969 1037 1205 2390 3916 1578 2313 2433 885 1097 1820 739 4483 3241 3861 1547 665 1449 4133 4877 1005 3510 18...

output:

188595
209663
209663
209663
209663
209663
209282
209663
209663
176195
156041
141623
176195
209663
209663
209282
175706
209663
209663
209663
209663
209663
209282
209663
209663
209663
188595
209282
209663
183686
209663
163197
209663
183686
209663
183686
209663
175706
209663
209663
209663
209663
209663...

result:

ok 3724 lines

Subtask #2:

score: 0
Wrong Answer

Test #3:

score: 0
Wrong Answer
time: 370ms
memory: 30224kb

input:

200000 10 200000
55651 97298 108697 86619 60721 199951 10610 162267 154301 138848 39191 18605 101369 57073 34977 101576 71252 143401 89587 160521 166491 38442 150761 35579 25571 121311 38033 38483 144639 41401 179161 54872 157905 137601 46863 187656 171901 43715 41036 150741 69057 102031 130561 4772...

output:

1232419
1222519
1232419
1232419
1232419
1232419
1232419
1232419
1232419
1232419
1040511
1148070
1232419
1232419
1232419
1232419
1206368
1206368
1232419
1232419
1232419
1222519
1167757
1206368
1214212
1222519
1232419
1222519
1222519
1160928
1011843
1232419
1232419
1189403
1222519
1232419
1222519
1148...

result:

wrong answer 731st lines differ - expected: '973226', found: '856342'

Subtask #3:

score: 20
Accepted

Test #5:

score: 20
Accepted
time: 238ms
memory: 32552kb

input:

200000 20000 200000
30681 32496 35471 48191 159123 69792 120915 150673 187226 158493 36275 26856 107976 124777 145229 69745 183961 14497 144808 153612 185893 137681 66417 46802 19345 113322 168046 128149 191001 135433 13201 139214 59489 81178 42343 163158 110121 119201 97501 53079 158755 192241 1132...

output:

46702944
46702944
38383720
38615532
38615532
42801975
39035571
46702944
46702944
46702944
27438528
38402892
46702944
46702944
42801975
42323113
39035571
42323113
46702944
46702944
46702944
41821993
46702944
34075405
46702944
38615532
46702944
28680653
46702944
42801975
42801975
38025842
46702944
467...

result:

ok 200000 lines

Test #6:

score: 0
Accepted
time: 235ms
memory: 32380kb

input:

200000 20000 200000
35105 74665 63960 162062 164953 63344 145369 115837 108866 61866 110690 123641 106889 65531 115933 163273 7531 128251 158561 169221 149787 40911 54465 92737 73473 10609 62701 89599 40007 40272 7318 129047 171198 90131 111281 85645 174001 140289 135851 26785 136485 31989 16313 888...

output:

43816163
35764822
45394839
45394839
45394839
43816163
45394839
43816163
40900280
38802753
45394839
45394839
43816163
34715395
45394839
43816163
43816163
45394839
43816163
45394839
45394839
43816163
35764822
45394839
43816163
43816163
16638306
45394839
35764822
45394839
34921501
45394839
45394839
409...

result:

ok 200000 lines

Test #7:

score: 0
Accepted
time: 244ms
memory: 32196kb

input:

200000 20000 200000
80203 178041 44172 21001 54489 120807 60663 147301 166763 49071 98913 115641 30627 164382 54165 165057 46105 9628 57953 86346 8273 137848 44871 119728 107309 132201 72483 198451 58505 185062 27039 49401 172444 101505 180973 59256 44859 53105 195233 161425 132423 2566 189331 15869...

output:

44318499
33827474
43556508
44318499
43556508
38914187
44318499
43556508
47858466
44318499
40709211
43556508
35706654
43556508
44318499
44318499
47858466
44318499
35359541
43556508
43556508
43556508
47858466
31755901
43556508
44318499
43556508
43556508
44318499
44318499
44318499
44318499
43556508
443...

result:

ok 200000 lines

Test #8:

score: 0
Accepted
time: 266ms
memory: 32656kb

input:

200000 20000 200000
69757 155771 81753 9285 168151 179881 122502 198324 140481 33185 155861 173423 117211 80727 63754 167913 121921 185921 182266 24801 167005 191511 77176 176741 117041 42534 10209 6241 83970 67652 164225 155249 125057 23841 71911 133150 79732 125061 7111 29841 142343 129299 155501 ...

output:

54623112
54623112
54623112
36983972
41889300
49604086
43664569
54623112
42438674
39404039
43664569
35418806
43664569
54623112
49604086
49604086
42438674
54623112
54623112
33869050
54623112
42438674
36847615
39404039
54623112
54623112
43664569
49604086
42438674
54623112
54623112
43664569
49604086
424...

result:

ok 200000 lines

Subtask #4:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #9:

score: 0
Wrong Answer
time: 66ms
memory: 17348kb

input:

50000 1000 50000
22098 40691 15626 6766 15467 15377 43375 7991 25841 6053 2031 38833 19761 42385 9421 28399 42001 15985 31206 30047 14001 7441 8377 5217 4402 37695 41393 25926 38137 32913 23203 31265 31401 32772 32905 24167 5233 24058 41685 26999 41 18461 15721 49365 49676 3151 29237 22894 37323 272...

output:

2734990
-721706355
2469610
1855857
2734990
2734990
-788687012
2734990
1967019
2734990
2469610
2469610
2388133
1799671
2469610
2734990
2734990
2734990
1957691
-403158197
2273183
1952934
2734990
2168141
2273183
2436566
-620683318
2734990
2469610
2469610
2273183
1986640
-112267267
2734990
2152587
21525...

result:

wrong answer 2nd lines differ - expected: '2469610', found: '-721706355'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%