QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#641909#6230. 水池Elegia100 ✓294ms302580kbC++146.3kb2024-10-15 03:15:482024-10-15 03:15:49

Judging History

你现在查看的是最新测评结果

  • [2024-10-15 03:15:49]
  • 评测
  • 测评结果:100
  • 用时:294ms
  • 内存:302580kb
  • [2024-10-15 03:15:48]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &x : v)
    is >> x;
  return is;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int INF = numeric_limits<int>::max();

const int N = 200010, L = 20;

const int NO = 0, FI = 1, LF = 2, RF = 3;

namespace SEG {

struct Node {
  int v;
  char typ;
  union {
    struct { int lb, rb; };
    int b[2];
  };
  union {
    struct { int ls, rs; };
    int s[2];
  };
} P[N * L * 8];

int top;

void updB(int o) {
  for (int i = 0; i < 2; ++i)
    P[o].b[i] = max(P[P[o].ls].b[i], P[P[o].rs].b[i]);
}

int build(int* beg, int* ed) {
  int ret = ++top;
  if (ed - beg == 1) {
    P[ret].lb = *beg;
    P[ret].rb = *ed;
    return ret;
  }
  int sz = ed - beg;
  P[ret].ls = build(beg, beg + (sz >> 1));
  P[ret].rs = build(beg + (sz >> 1), ed);
  updB(ret);
  return ret;
}

int cpy(int o) {
  int ret = ++top;
  memcpy(P + ret, P + o, sizeof(Node));
  return ret;
}

void pd(int o) {
  if (P[o].typ == NO) return;
  for (int i = 0; i < 2; ++i)
    P[o].s[i] = cpy(P[o].s[i]);
  if (P[o].typ == FI) {
    for (int i = 0; i < 2; ++i) {
      P[P[o].s[i]].typ = FI;
      P[P[o].s[i]].v = P[o].v;
    }
    P[o].typ = NO;
    return;
  }
  int dir = P[o].typ - LF;
  int cur = P[o].v, p = !dir;
  P[P[o].ls].typ = P[P[o].rs].typ = LF + dir;
  do {
    P[P[o].s[p]].v = cur;
    cur = max(cur, P[P[o].s[p]].b[dir]);
    p = !p;
  } while (p != !dir);
  P[o].typ = NO;
}

template <bool DIR>
int chB(int o, int l, int r, int k, int x) {
  o = cpy(o);
  if (l == r) {
    P[o].b[DIR] = x;
    return o;
  }
  int mid = (l + r - 1) >> 1;
  pd(o);
  if (k <= mid)
    P[o].ls = chB<DIR>(P[o].ls, l, mid, k, x);
  else
    P[o].rs = chB<DIR>(P[o].rs, mid + 1, r, k, x);
  updB(o);
  return o;
}

template <bool DIR>
int bound(int o, int l, int r, int x) {
  if (P[o].b[DIR] < x) return -1;
  if (l == r) return l;
  int mid = (l + r - 1) >> 1;
  int ret = bound<DIR>(P[o].s[!DIR], !DIR ? (mid + 1) : l, !DIR ? r : mid, x);
  if (ret == -1)
    ret = bound<DIR>(P[o].s[DIR], DIR ? (mid + 1) : l, DIR ? r : mid, x);
  return ret;
}

template <bool DIR>
int bound(int o, int l, int r, int k, int x) {
  if (P[o].b[DIR] < x) return -1;
  if (l == r) return l;
  int mid = (l + r - 1) >> 1;
  int ret;
  if (k <= mid) {
    ret = bound<DIR>(P[o].ls, l, mid, k, x);
    if (ret == -1 && DIR == 1)
      ret = bound<DIR>(P[o].rs, mid + 1, r, x);
  } else {
    ret = bound<DIR>(P[o].rs, mid + 1, r, k, x);
    if (ret == -1 && DIR == 0)
      ret = bound<DIR>(P[o].ls, l, mid, x);
  }
  return ret;
}

int fil(int o, int l, int r, int ql, int qr, int x) {
  o = cpy(o);
  if (ql == l && qr == r) {
    P[o].v = x;
    P[o].typ = FI;
    return o;
  }
  int mid = (l + r - 1) >> 1;
  pd(o);
  if (qr <= mid)
    P[o].ls = fil(P[o].ls, l, mid, ql, qr, x);
  else if (ql > mid)
    P[o].rs = fil(P[o].rs, mid + 1, r, ql, qr, x);
  else {
    P[o].ls = fil(P[o].ls, l, mid, ql, mid, x);
    P[o].rs = fil(P[o].rs, mid + 1, r, mid + 1, qr, x);
  }
  return o;
}

int res;

int query(int o, int l, int r, int k) {
  o = cpy(o);
  if (l == r) {
    res = P[o].v;
    return o;
  }
  int mid = (l + r - 1) >> 1;
  pd(o);
  if (k <= mid)
    P[o].ls = query(P[o].ls, l, mid, k);
  else
    P[o].rs = query(P[o].rs, mid + 1, r, k);
  return o;
}

template <bool DIR>
int pr(int o, int l, int r, int ql, int qr) {
  o = cpy(o);
  if (ql == l && qr == r) {
    P[o].v = res;
    P[o].typ = LF + DIR;
    res = max(res, P[o].b[DIR]);
    return o;
  }
  int mid = (l + r - 1) >> 1;
  pd(o);
  if (qr <= mid)
    P[o].ls = pr<DIR>(P[o].ls, l, mid, ql, qr);
  else if (ql > mid)
    P[o].rs = pr<DIR>(P[o].rs, mid + 1, r, ql, qr);
  else {
    if (DIR) {
      P[o].ls = pr<DIR>(P[o].ls, l, mid, ql, mid);
      P[o].rs = pr<DIR>(P[o].rs, mid + 1, r, mid + 1, qr);
    } else {
      P[o].rs = pr<DIR>(P[o].rs, mid + 1, r, mid + 1, qr);
      P[o].ls = pr<DIR>(P[o].ls, l, mid, ql, mid);
    }
  }
  return o;
}

}

int h[N];
int rf[N];

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, q;
  cin >> n >> q;
  for (int i = 1; i < n; ++i)
    cin >> h[i];
  h[0] = h[n] = INF;
  rf[0] = SEG::build(h, h + n);
  for (int j = 1; j <= q; ++j) {
    int opt, i, x, ht;
    cin >> opt >> i >> x;
    int o = rf[i];
    if (opt == 0) {
      cin >> ht;
      o = SEG::query(o, 1, n, x);
      if (SEG::res < ht) {
        int l = SEG::bound<0>(o, 1, n, x, ht);
        int r = SEG::bound<1>(o, 1, n, x, ht);
        //if (ht == 832154179) {
        //  cerr<<"TELL YOU "<<SEG::res<<'\n';
       // }
        //cerr << ht << " cover " << l << ' ' << r << '\n';
        o = SEG::fil(o, 1, n, l, r, ht);
      }
    } else if (opt == 1) {
      o = SEG::query(o, 1, n, x);
      int l = SEG::bound<0>(o, 1, n, x, SEG::res);
      int r = SEG::bound<1>(o, 1, n, x, SEG::res);
      //cerr << "SHRINK " << l << " - " << x << " - " << r << '\n';
      SEG::res = 0;
      o = SEG::pr<0>(o, 1, n, l, x);
      SEG::res = 0;
      o = SEG::pr<1>(o, 1, n, x, r);
    } else if (opt == 2) {
      cin >> ht;
      o = SEG::chB<1>(o, 1, n, x, ht);
      o = SEG::chB<0>(o, 1, n, x + 1, ht);
    } else {
      o = SEG::query(o, 1, n, x);
      cout << SEG::res << '\n';
    }
    rf[j] = o;
  }

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 5756kb

input:

451 469
799643869 554074088 313641255 240396194 289441005 120760635 60081214 502510219 361989963 460382686 31603393 669782854 307229342 102537485 383822174 40855518 1920840 158219655 284013679 702705326 126997001 742365412 188287595 162194743 73323070 549981194 165910073 731839013 534419392 57360831...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
594356061
0
804870752
0
804870752
0
0
0
804870752
0
0
0
0
804870752
0
0
0
0
0
804870752
0
0
0
0
0
942707062
0
759661577
804870752
0
0
0
0
0
804870752
0
0
0
0
0
0
0
0
822278415
0
0
0
0
0
0
0
0
0
0
0
799340058
0
0
0
0
0
825762297
0
0
988334505
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 109 lines

Test #2:

score: 10
Accepted
time: 1ms
memory: 3856kb

input:

500 500
110684039 714931609 533911161 0 265901115 0 251023653 590971317 277168628 585419312 487607060 435315504 0 744143837 12965575 572937978 741703253 13735189 797368949 459961108 742132282 0 531131304 366695217 338399129 193691768 0 637582051 541803135 375457677 212577416 272671034 292647642 1487...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
936016342
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
936016342
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
791442473
0
0
0
0
936016342
0
0
0
0
0
0
0
0
0
0
791442473
0
0
0
0
0
911111000
0
0
0
0
0
0
0
0
0
0
0

result:

ok 118 lines

Subtask #2:

score: 10
Accepted

Test #3:

score: 10
Accepted
time: 75ms
memory: 69856kb

input:

95763 92359
125406791 137432093 763265172 540984217 511101218 287278210 710943263 68325782 406866215 71018028 455549862 170376172 648802381 58005284 512058297 302287320 101566189 243586504 27102305 451590266 493939605 180158978 528068209 118140458 337869225 487573956 40596884 178126990 0 75901163 0 ...

output:

0
0
0
847010708
847010708
847010708
847010708
847010708
847010708
847010708
847010708
847010708
847010708
847010708
847010708
847010708
847010708
847010708
847010708
847010708
979001576
979001576
979001576
979001576
979001576
979001576
979001576
979001576
979001576
979001576
979001576
979001576
9790...

result:

ok 30924 lines

Test #4:

score: 10
Accepted
time: 82ms
memory: 76864kb

input:

100000 100000
182316754 57847370 371997054 688666687 609463280 221731325 730947425 110591072 614905016 85202512 565786410 324688115 540194644 638713991 231708549 624348478 256736039 720264041 298036855 502549155 432134123 250880358 457573593 112649815 539008726 551072540 265324815 122503149 21017445...

output:

0
0
0
0
0
0
0
0
0
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
984622156
98...

result:

ok 33344 lines

Subtask #3:

score: 10
Accepted

Test #5:

score: 10
Accepted
time: 181ms
memory: 142332kb

input:

191995 194162
6891432 785450979 569857716 132255242 408871731 773453690 0 725347657 721477690 100255432 288415418 189257011 618042073 105998740 571269928 163803278 735085310 341019627 86391267 213232540 520854480 535331204 295794830 534945203 582403708 799435263 94893592 454575997 290616581 76159076...

output:

0
0
0
884127445
884127445
884127445
884127445
884127445
884127445
884127445
910351084
910351084
910351084
910351084
910351084
910351084
935893688
935893688
973784603
973784603
973784603
973784603
973784603
973784603
973784603
973784603
973784603
973784603
973784603
973784603
973784603
973784603
9737...

result:

ok 64839 lines

Test #6:

score: 10
Accepted
time: 203ms
memory: 158900kb

input:

200000 200000
331609764 519737970 542759683 661337161 780296503 111617312 341044745 121460126 293351903 176782177 28743091 687291220 289926509 184245329 12289121 87979687 440078318 222463041 535563010 444391851 397642670 37645035 534850362 268288380 73231693 197995311 41607131 0 124680778 585095862 ...

output:

0
0
0
0
0
0
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
979323483
97932348...

result:

ok 66866 lines

Subtask #4:

score: 10
Accepted

Test #7:

score: 10
Accepted
time: 91ms
memory: 104152kb

input:

99057 99999
517200151 696399345 261176143 785161725 271341444 494132142 612344628 269719211 502358914 251918663 742118731 241849533 212679882 459839985 12090935 693695879 461541162 116365447 508973475 515271458 135064622 2780057 564671685 549876910 62487209 138469672 382327654 298983886 597058598 53...

output:

0
0
0
887051469
887051469
0
0
887051469
0
0
887051469
887051469
952407352
0
0
0
887051469
887051469
0
0
0
0
887051469
0
992313609
0
0
0
0
0
887051469
0
910902455
0
0
921403619
0
0
0
0
0
0
0
887051469
887051469
0
0
0
0
0
887051469
0
0
0
887051469
0
0
0
0
0
921403619
0
0
0
0
0
0
0
0
0
0
0
0
0
0
966047...

result:

ok 33387 lines

Test #8:

score: 10
Accepted
time: 98ms
memory: 95004kb

input:

100000 100000
461059606 540059181 7250610 204202763 787877238 472431241 101358156 0 204229822 0 621692033 171620107 86420408 764400907 170400333 678690827 230462968 396177666 341506213 94245985 715367743 280551095 466166741 47784281 786602178 108907121 204832987 716071824 227479970 70311291 25702414...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
992618692
0
0
0
0
0
0
0
915689862
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
981821779
0
0
0
0
0
0
0
0
0
0
0
800504036
0
0
0
0
0
0
0
0
0
0
0
981821779
0
0
0
0
0
0
992618692
0
0
0
992618692
0
0
0
0
0
0
0
0
0
0
0
0
0
0
893647271
0
0
0
0
800504036
0
0
0
0
0
0
0
0
0
0
0
0
0
0
915689862
...

result:

ok 33091 lines

Subtask #5:

score: 10
Accepted

Test #9:

score: 10
Accepted
time: 221ms
memory: 201196kb

input:

181439 182363
173196455 791637307 117409078 351254963 478560653 628560153 328836651 691159128 452914849 263276613 326224528 96034236 321262200 459154368 428625104 56828416 195992385 667170842 119347528 791746400 510061732 562219507 546684168 0 0 378219232 710998173 80970604 211767056 196090065 40580...

output:

0
0
835426981
891453835
0
835426981
0
835426981
0
0
0
0
0
0
811280029
0
0
891453835
0
891453835
0
859764426
914625510
0
0
835426981
0
0
0
0
0
835426981
910021852
835426981
0
881109467
910021852
0
0
0
0
891453835
891453835
0
891453835
0
0
0
835426981
891453835
891453835
835426981
0
0
0
0
0
944598797
...

result:

ok 60724 lines

Test #10:

score: 10
Accepted
time: 259ms
memory: 207660kb

input:

200000 200000
297437054 403025301 368090158 40940851 279326662 681701299 358384167 196990140 238228111 684919076 146001429 2169871 120615282 561896410 603331321 479661469 388977899 471343388 73406029 47308543 570843036 21701057 763085377 11111897 728503920 48557475 425363790 459563986 695136532 2100...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
824187730
824187730
928356457
0
0
0
0
824187730
0
0
0
0
0
0
0
0
0
928356457
824187730
0
0
0
824187730
928356457
0
824187730
0
824187730
0
824187730
0
0
0
0
0
0
0
0
0
0
824187730
0
0
0
0
813117933
928356457
0
824187730
0
0
0
824187730
0
0
0
0
0
0
824187730
0
0
824187...

result:

ok 66287 lines

Subtask #6:

score: 10
Accepted

Test #11:

score: 10
Accepted
time: 115ms
memory: 143520kb

input:

98129 95480
377412122 244725955 643347743 443420782 692782024 648529351 480738121 610089060 168296682 127083079 298579894 499233289 172744990 692910923 674931085 235605842 62064826 326190240 653620748 35477505 743746455 755958773 127706397 957977 19774381 761269692 390855319 499181449 309977179 1504...

output:

799853979
799853979
799991463
799882995
799991090
953748311
953748311
847547702
847547702
847547702
799937068
918190491
953459468
799974711
794595152
799974711
799979330
945858926
799991090
807846915
799869431
807846915
798774276
799990837
807846915
799974711
799974711
799829385
869140301
799974711
...

result:

ok 23717 lines

Test #12:

score: 10
Accepted
time: 114ms
memory: 149428kb

input:

100000 100000
167477758 264267871 100124926 742554512 212332615 207962311 266287025 0 723891187 264737800 489993210 46768383 711531845 597886241 94339432 739789203 9944251 332945883 163074201 15451510 626941230 144533275 746978999 458926381 364414493 213232433 652133392 784249280 38161734 203360881 ...

output:

875557009
875557009
799965061
799997694
799590354
799815038
799983693
799590354
799815038
798814193
799997694
799952176
799997694
901186215
901186215
798093807
901186215
901186215
901186215
832154179
796655713
988184845
988184845
796353870
799295591
799814850
799554264
965413730
965413730
933272434
...

result:

ok 24937 lines

Subtask #7:

score: 10
Accepted

Test #13:

score: 10
Accepted
time: 275ms
memory: 296816kb

input:

196745 190192
530816289 110623315 28195048 522299730 569972702 61450893 11096188 243864530 511796004 641282498 128651835 596974715 206386531 420103078 794908692 3553871 22531630 405072789 284074824 701448666 52894648 660047723 449993619 155359896 495406323 732280568 278218962 0 631425418 782081407 6...

output:

0
0
0
0
0
0
0
0
0
0
0
970084489
970084489
799989527
799997786
799988922
799839940
799997786
799988922
799969994
799931595
799969994
799854853
799088164
799922822
799565376
799942064
799955254
799948527
799931595
799948527
799955254
799904950
798510076
799955254
799862468
799805833
881681817
80481007...

result:

ok 47960 lines

Test #14:

score: 10
Accepted
time: 264ms
memory: 302580kb

input:

200000 200000
673127377 0 77451016 775484256 736601578 541744599 279188941 376199450 445000385 536297448 153534439 580187997 385793985 117159253 283715734 110189111 477062829 109589572 614350587 283219700 524348102 773262964 543305836 637637693 210841569 447471156 483271957 58427240 240140473 184516...

output:

862269466
862269466
862269466
799967081
997552036
799964703
799964703
799964703
799893079
799647832
799826182
799973810
799800846
799291812
799943676
799977716
799977716
799977716
799973810
799913333
798104330
799540484
799973810
799977716
799977716
798776407
799964703
799640647
799587455
799964703
...

result:

ok 50277 lines

Subtask #8:

score: 10
Accepted

Test #15:

score: 10
Accepted
time: 269ms
memory: 251228kb

input:

192247 195207
283700978 375630805 304536900 656995707 349419833 708624942 672433502 520674515 764718893 239174457 133144085 330437569 746169379 70258518 594755714 90821371 135440873 284046069 13226018 205346297 580203021 165858312 328670472 369986775 626061182 147106705 233473844 284462500 125956912...

output:

0
0
0
0
0
0
0
0
946220849
946220849
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
946220849
0
0
799990822
0
0
0
0
0
0
946220849
0
799990822
0
0
0
0
0
0
799953664
0
946220849
0
0
0
0
0
799940247
0
0
0
0
0
0
0
0
0
0
799940247
0
0
0
799942744
0
0
799996570
0
0
0
940226739
0
0
0
0
0
0
0
0
0
0
0
946220849
0
0
0
94622084...

result:

ok 48681 lines

Subtask #9:

score: 10
Accepted

Test #16:

score: 10
Accepted
time: 294ms
memory: 277792kb

input:

200000 200000
528930985 235973207 466767467 402016659 317374245 250837951 507340678 253656348 258016597 272673016 79972069 655199701 467655017 688146502 333191236 297745886 269247236 233526144 566947127 342438540 474935181 287475130 95235847 489947025 608569833 225058316 314312314 672017306 34789162...

output:

805427480
0
0
805427480
0
0
0
0
964622001
0
0
0
0
0
805427480
805427480
799994308
964622001
805427480
799994308
0
0
0
964622001
0
0
0
799895625
805427480
799929656
0
0
0
805427480
799994308
805427480
0
0
0
0
0
0
0
0
799991835
921331629
799994308
799993783
805427480
0
0
805427480
0
964622001
0
0
0
0
...

result:

ok 49987 lines

Subtask #10:

score: 10
Accepted

Test #17:

score: 10
Accepted
time: 220ms
memory: 219288kb

input:

184466 180121
569024790 424341620 582247894 789997908 153645772 751624335 110488345 438497535 636816851 719408027 662734779 195349431 490536701 88364290 270826575 500058722 422096895 323370242 726020946 132560652 77857301 685544859 898126 517051590 207213973 305119180 230392425 292421735 763994110 6...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
852790406
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
852790406
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
916697584
0
0
0
0
0
0
0
0
852790406
0
0
820039801
0
0
0
0
0
0
0
0
0
0
0
0
976709850
852790406
0
0
0
0
0
0
0
0
0
927569861
...

result:

ok 45001 lines

Test #18:

score: 10
Accepted
time: 291ms
memory: 246524kb

input:

200000 200000
57075583 318936234 385933100 284771289 437702009 621634712 517117387 0 774832313 262099632 474490840 255576398 0 423845387 564382296 457879822 589921402 192446326 62929863 121735185 374224043 650575595 741523547 208040608 598312128 79970456 381666526 708478481 427989596 490641985 15784...

output:

0
0
0
0
0
0
811560873
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
836460368
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
818096352
0
0
0
0
818096352
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
989979212
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
963130222
0
799997224
98...

result:

ok 49831 lines