QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188733#4918. 染色hos_lyric15 767ms177216kbC++149.1kb2023-09-26 12:40:572023-09-26 12:40:57

Judging History

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

  • [2023-09-26 12:40:57]
  • 评测
  • 测评结果:15
  • 用时:767ms
  • 内存:177216kb
  • [2023-09-26 12:40:57]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


using U = unsigned long long;

int N, M, Q;
vector<int> O, L, R, X;
vector<U> V;


namespace brute {
vector<U> run() {
  vector<set<int>> on(N);
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= M; ++j) {
      on[i].insert(j);
    }
  }
  vector<U> ws(N, 0);
  vector<U> ans(Q, 0);
  for (int q = 0; q < Q; ++q) {
    if (O[q] == 1) {
      for (int i = L[q]; i < R[q]; ++i) on[i].erase(X[q]);
    } else if (O[q] == 2) {
      for (int i = L[q]; i < R[q]; ++i) on[i].insert(X[q]);
    } else if (O[q] == 3) {
      int mn = M + 1;
      for (int i = L[q]; i < R[q]; ++i) chmin(mn, *on[i].begin());
      for (int i = L[q]; i < R[q]; ++i) if (mn == *on[i].begin()) ws[i] += V[q];
    } else {
      for (int i = L[q]; i < R[q]; ++i) ans[q] += ws[i];
    }
// for(int i=0;i<N;++i){cerr<<i<<": ";pv(on[i].begin(),on[i].end());}
  }
  return ans;
}
}  // brute


namespace fast {
struct Node {
  priority_queue<int, vector<int>, greater<int>> que, queRem;
  int mn;
  int cnt, cntAll;
  U sum, lz, lzAll;
  Node() : que{}, queRem{}, mn(M + 1), cnt(0), cntAll(0), sum(0), lz(0), lzAll(0) {}
  void push(Node &l, Node &r) {
    if (lz) {
      assert(mn <= que.top());
      if (mn == que.top()) {
        l.addAll(lz);
        r.addAll(lz);
      } else {
        if (mn == l.mn) l.add(lz);
        if (mn == r.mn) r.add(lz);
      }
      lz = 0;
    }
    if (lzAll) {
      l.addAll(lzAll);
      r.addAll(lzAll);
      lzAll = 0;
    }
  }
  void pull(const Node &l, const Node &r) {
    const int mnL = min(que.top(), l.mn);
    const int mnR = min(que.top(), r.mn);
    if (mnL < mnR) {
      mn = mnL;
      cnt = l.cnt;
    } else if (mnL > mnR) {
      mn = mnR;
      cnt = r.cnt;
    } else {
      mn = mnL;
      cnt = l.cnt + r.cnt;
    }
    cntAll = l.cntAll + r.cntAll;
    sum = l.sum + r.sum;
  }
  void paint(int x, int col) {
    (col ? que : queRem).push(x);
    for (; !queRem.empty() && que.top() == queRem.top(); que.pop(), queRem.pop()) {}
    // for leaf
    mn = que.top();
  }
  void add(U val) {
    sum += cnt * val;
    lz += val;
  }
  void addAll(U val) {
    sum += cntAll * val;
    lzAll += val;
  }
};

int segN;
vector<Node> seg;
void push(int u) {
  if (u < segN) seg[u].push(seg[u << 1], seg[u << 1 | 1]);
}
void pull(int u) {
  if (u < segN) seg[u].pull(seg[u << 1], seg[u << 1 | 1]);
}
void paint(int u, int l, int r, int a, int b, int x, int col) {
  if (b <= l || r <= a) return;
  push(u);
  if (a <= l && r <= b) {
    seg[u].paint(x, col);
    pull(u);
    return;
  }
  const int mid = (l + r) / 2;
  paint(u << 1    , l, mid, a, b, x, col);
  paint(u << 1 | 1, mid, r, a, b, x, col);
  pull(u);
}
void paint(int a, int b, int x, int col) {
  paint(1, 0, segN, a, b, x, col);
}
void add(int u, int l, int r, int a, int b, int tar, int anc, U val) {
// cerr<<"add "<<u<<" ["<<l<<", "<<r<<") ["<<a<<", "<<b<<") tar="<<tar<<" anc="<<anc<<" val="<<val<<endl;
  if (b <= l || r <= a) return;
  push(u);
  if (a <= l && r <= b) {
    const int mn = min(anc, seg[u].mn);
    assert(tar <= mn);
    if (tar == mn) {
// cerr<<"  added ["<<l<<", "<<r<<") tar="<<tar<<" anc="<<anc<<" seg[u].mn="<<seg[u].mn<<" mn="<<mn<<endl;
      if (tar == anc) {
        seg[u].addAll(val);
      } else {
        seg[u].add(val);
      }
    }
    return;
  }
  chmin(anc, seg[u].que.top());
  const int mid = (l + r) / 2;
  add(u << 1    , l, mid, a, b, tar, anc, val);
  add(u << 1 | 1, mid, r, a, b, tar, anc, val);
  pull(u);
}
void add(int a, int b, int tar, int anc, U val) {
  add(1, 0, segN, a, b, tar, anc, val);
}
int getMin(int u, int l, int r, int a, int b) {
  if (b <= l || r <= a) return M + 1;
  if (a <= l && r <= b) return seg[u].mn;
  push(u);
  const int mid = (l + r) / 2;
  const int resL = getMin(u << 1    , l, mid, a, b);
  const int resR = getMin(u << 1 | 1, mid, r, a, b);
  pull(u);
  return min(seg[u].que.top(), min(resL, resR));
}
int getMin(int a, int b) {
  return getMin(1, 0, segN, a, b);
}
U getSum(int u, int l, int r, int a, int b) {
  if (b <= l || r <= a) return 0;
  if (a <= l && r <= b) return seg[u].sum;
  push(u);
  const int mid = (l + r) / 2;
  const U resL = getSum(u << 1    , l, mid, a, b);
  const U resR = getSum(u << 1 | 1, mid, r, a, b);
  pull(u);
  return resL + resR;
}
U getSum(int a, int b) {
  return getSum(1, 0, segN, a, b);
}

vector<U> run() {
  for (segN = 1; segN < N; segN <<= 1) {}
  seg.assign(segN << 1, Node());
  for (int u = 1; u < segN << 1; ++u) seg[u].que.push(M + 1);
  for (int i = 0; i < N; ++i) seg[segN + i].cnt = seg[segN + i].cntAll = 1;
  for (int u = segN; --u >= 1; ) pull(u);
  vector<set<pair<int, int>>> pss(M + 1);
  for (int x = 0; x <= M; ++x) {
    paint(0, N, x, 1);
    pss[x].emplace(N, -0);
  }
#ifdef LOCAL
vector<vector<int>>board(M,vector<int>(N,1));
#endif
  vector<U> ans(Q, 0);
  for (int q = 0; q < Q; ++q) {
    if (O[q] == 1) {
// cerr<<COLOR("33")<<O[q]<<" ["<<L[q]<<", "<<R[q]<<") "<<X[q]<<COLOR()<<endl;
      const int x = X[q];
      const int l = L[q], r = R[q];
      int psLen = 0;
      pair<int, int> ps[2];
      for (auto it = pss[x].lower_bound(make_pair(l, l)); it != pss[x].end(); it = pss[x].erase(it)) {
        const int ll = -it->second, rr = it->first;
        if (r <= ll) break;
        if (ll < l) ps[psLen++] = make_pair(l, -ll);
        if (r < rr) ps[psLen++] = make_pair(rr, -r);
        paint(ll, rr, x, 0);
      }
      for (int j = 0; j < psLen; ++j) {
        const int ll = -ps[j].second, rr = ps[j].first;
        paint(ll, rr, x, 1);
        pss[x].insert(ps[j]);
      }
#ifdef LOCAL
for(int i=L[q];i<R[q];++i)board[X[q]][i]=0;
int sum=0;
for(int i=0;i<N;++i)sum+=board[X[q]][i];
for(const auto&p:pss[X[q]])for(int i=-p.second;i<p.first;++i){assert(board[X[q]][i]);--sum;}
assert(sum==0);
#endif
    } else if (O[q] == 2) {
// cerr<<COLOR("33")<<O[q]<<" ["<<L[q]<<", "<<R[q]<<") "<<X[q]<<COLOR()<<endl;
      const int x = X[q];
      int l = L[q], r = R[q];
      for (auto it = pss[x].lower_bound(make_pair(l, l)); it != pss[x].end(); it = pss[x].erase(it)) {
        const int ll = -it->second, rr = it->first;
        if (r <= ll) break;
        paint(ll, rr, x, 0);
        chmin(l, ll);
        chmax(r, rr);
      }
      paint(l, r, x, 1);
      pss[x].emplace(r, -l);
#ifdef LOCAL
for(int i=L[q];i<R[q];++i)board[X[q]][i]=1;
int sum=0;
for(int i=0;i<N;++i)sum+=board[X[q]][i];
for(const auto&p:pss[X[q]])for(int i=-p.second;i<p.first;++i){assert(board[X[q]][i]);--sum;}
assert(sum==0);
#endif
    } else if (O[q] == 3) {
// cerr<<COLOR("33")<<O[q]<<" ["<<L[q]<<", "<<R[q]<<") "<<V[q]<<COLOR()<<endl;
      const int tar = getMin(L[q], R[q]);
      add(L[q], R[q], tar, M + 1, V[q]);
#ifdef LOCAL
vector<int>mns(N,M);
for(int x=0;x<M;++x)for(int i=0;i<N;++i)if(board[x][i])chmin(mns[i],x);
cerr<<"  mns = "<<mns<<endl;
cerr<<"  tar = "<<tar<<endl;
#endif
    } else {
      ans[q] = getSum(L[q], R[q]);
    }
  }
  return ans;
}
}  // fast


int main() {
  for (; ~scanf("%d%d", &N, &Q); ) {
    O.resize(Q);
    L.resize(Q);
    R.resize(Q);
    X.assign(Q, -1);
    V.assign(Q, 0);
    for (int q = 0; q < Q; ++q) {
      scanf("%d%d%d", &O[q], &L[q], &R[q]);
      --L[q];
      if (O[q] == 1 || O[q] == 2) {
        scanf("%d", &X[q]);
        --X[q];
      } else if (O[q] == 3) {
        scanf("%llu", &V[q]);
      }
    }
    M = max(*max_element(X.begin(), X.end()), 0) + 1;
cerr<<"N = "<<N<<", M = "<<M<<", Q = "<<Q<<endl;
    
    const auto ans = fast::run();
    for (int q = 0; q < Q; ++q) if (O[q] == 4) {
      printf("%llu\n", ans[q]);
    }
#ifdef LOCAL
if(N<=1000&&Q<=1000){
 const auto brt=brute::run();
 for(int q=0;q<Q;++q)if(brt[q]!=ans[q]){cerr<<q<<": "<<brt[q]<<" "<<ans[q]<<endl;break;}
 assert(brt==ans);
}
#endif
  }
  return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 4336kb

input:

1000 1000
3 722 914 2141556875752121755
3 323 347 6433743606947304931
2 142 206 439
2 117 840 195
2 127 502 56
3 168 707 15142638115094015116
4 190 257
2 88 976 475
1 319 867 351
1 682 889 409
2 406 446 196
3 28 35 4899387534800369959
2 291 546 150
1 528 617 128
1 58 122 251
2 381 400 276
4 510 958
...

output:

15128467772367689008
17361914246216994339
5483226026482017320
3033562207293358603
2081407883485577238
7431958406282818646
4664359672511637691
9795059641150632690
17884251128335023776
3389445997760709607
15161173652136060523
17246899135664170339
16659472119973467421
5618344994614112283
92650283427734...

result:

wrong answer 8th words differ - expected: '8517692808398202534', found: '9795059641150632690'

Subtask #2:

score: 15
Accepted

Test #11:

score: 15
Accepted
time: 603ms
memory: 159404kb

input:

300000 300000
1 237576 237663 1
3 16150 16208 9270412155482010138
2 175648 175692 1
4 190836 190849
4 199010 199097
1 73976 298801 1
3 89902 89939 6418828085116455990
3 55415 55461 12238963685511262676
3 119825 119875 8146944792877919309
3 135103 135158 218634681842812119
3 127261 127352 13291431184...

output:

0
0
0
0
0
0
12272376591028786218
0
0
0
0
0
0
0
0
0
0
0
0
0
0
954290611784159519
0
3778617232493240005
8956067326602310519
7373452729428553855
16938285947326957203
0
0
14783754218831034862
7601682967357904165
0
0
0
0
0
0
11584905325916393312
0
0
4657169178464751085
17170356428308894805
0
0
0
0
148107...

result:

ok 74906 tokens

Test #12:

score: 0
Accepted
time: 606ms
memory: 159532kb

input:

300000 300000
3 51867 51899 1302529772508711959
1 163791 163805 1
1 176666 176684 1
2 127516 127575 1
4 31898 31983
3 151469 151497 15873092426332082486
3 206515 206568 14236701547576343621
4 238241 238324
3 61219 262809 1734847965363776922
2 220344 220393 1
2 98688 148993 1
4 55989 56049
3 298350 2...

output:

0
0
0
10681306550146550313
6652613657187526474
11475494508458717824
811486215804201182
1622972431608402364
0
15901103964711581888
3357820396972179286
4094176851202742427
5379446566603537422
16250215233565986824
15431111627897858304
0
16250215233565986824
4917765691823749552
0
0
10297212258427286974
...

result:

ok 74943 tokens

Test #13:

score: 0
Accepted
time: 601ms
memory: 159488kb

input:

300000 300000
4 86816 86819
1 226565 246677 1
3 251963 251987 4817512795078102720
3 17122 202813 12262635941537918815
4 101129 101139
4 171789 171859
2 44072 166207 1
3 171011 171050 9516143677767859845
3 222046 222082 7458232785251868808
4 52499 166730
3 222551 222640 2035040917841558853
1 242195 2...

output:

0
5761786840950245653
3650180384843309913
13470892551030562504
16546298263213309450
3861341030454003487
15279334389549148006
5972947486560939227
0
11734734327511184880
0
10784511422263063797
16229557294797269089
3861341030454003487
10256609808236329862
15173754066743801219
0
1804317071900187272
5936...

result:

ok 74976 tokens

Test #14:

score: 0
Accepted
time: 605ms
memory: 159720kb

input:

300000 300000
2 224303 224374 1
3 5249 5288 16547079035307299489
1 249405 249440 1
1 244932 244988 1
1 89040 89114 1
2 114166 114194 1
4 110077 110172
1 141920 141970 1
3 205203 205243 1118749945144490180
2 127281 127373 1
3 173359 173363 11110846146456890394
3 283255 283303 3242183420586937197
3 12...

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
2204476432060505976
0
0
0
0
0
0
0
0
0
6246016557504766932
3429185560983009296
0
0
0
0
0
0
0
0
8450492989565272908
0
0
0
244941825784500664
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
10672427856181146758
0
0
14782553786312832860
0
0
0
2449418257845006640
0
0...

result:

ok 74803 tokens

Test #15:

score: 0
Accepted
time: 559ms
memory: 159088kb

input:

300000 300000
1 220731 220734 1
3 219129 219133 1441661622928400529
4 297901 297906
3 226862 226869 2997910990656207321
2 154071 154073 1
1 239514 239523 1
2 264617 264626 1
1 66677 66680 1
2 108520 108527 1
2 493 498 1
3 93536 93536 1729223806369067100
1 99697 99702 1
1 98817 98817 1
2 268169 26817...

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
0
0
8523192685433180568
8523192685433180568
1420532114238863428
8523192685433180568
0
0
9943724799672043996
0
11364256913910907424
0
8523192685433180568
5682128456955453712
9943724799672043996
14205321142388634280
2841064228477726856
...

result:

ok 74996 tokens

Test #16:

score: 0
Accepted
time: 679ms
memory: 159604kb

input:

300000 300000
3 242005 245455 17402857150844839475
1 195499 202760 1
3 86348 87652 16350042050962992455
2 67513 70549 1
2 17581 20392 1
1 180566 187399 1
2 132424 136215 1
4 201 7568
4 29035 34787
4 159930 167082
4 117096 126668
3 115807 124052 6966836812432990399
4 24003 25402
3 16679 17045 1443793...

output:

0
0
0
0
0
0
0
0
0
0
1069304592552696348
0
0
0
0
0
18416266141863826215
0
0
0
3291332335248161760
0
355153960082695408
2339117343903337888
0
0
8313068146843994614
0
0
1842567308665326891
0
8807430591712594964
2810662510187183646
0
0
11269033645696727616
11110474990560302869
4659943295138724138
573269...

result:

ok 75196 tokens

Test #17:

score: 0
Accepted
time: 616ms
memory: 159508kb

input:

300000 300000
2 129524 130230 1
3 97829 98681 14177044200280537874
1 117004 117036 1
3 75080 75625 7953158225766026866
3 222342 223044 592691174623108465
4 297810 298422
4 182525 182999
4 107197 107449
4 26126 26883
3 292284 292507 2229113056122186954
2 80055 80745 1
1 9570 10222 1
2 171443 171566 1...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
6310142178115801295
0
0
0
0
0
0
0
0
0
14347829830854147244
0
0
0
0
0
0
0
0
3944750402169235976
0
0
14757788959901029185
1019326869378140182
0
0
0
0
10461260111479654801
0
0
16943243282109390662
0
0
0
7444098211629495683
16417881432838763511
10033696365246380464
15743721...

result:

ok 74887 tokens

Test #18:

score: 0
Accepted
time: 714ms
memory: 159508kb

input:

300000 300000
3 60899 273136 17900506015963226324
2 255340 262254 1
1 47804 166274 1
2 228603 279002 1
1 229031 276929 1
4 136197 298489
3 162024 257244 7401373630232006099
1 215974 227652 1
3 119149 204343 7745371782660146547
1 152630 214299 1
3 96818 230022 73641545834168695
1 216242 238152 1
4 84...

output:

18154335184155868016
4395498840986882932
6677517497004993358
9589498140629496089
7527637927391730952
7561535112473928655
10721089906023321737
14674898849238760964
7537937300108454874
2088977973872526664
12681955574796639580
865433786514001673
6128943734780039177
6057697509332298715
66303342836821411...

result:

ok 74979 tokens

Test #19:

score: 0
Accepted
time: 564ms
memory: 158212kb

input:

290000 290000
4 133423 133423
1 114519 114520 1
2 184800 184802 1
2 138774 138775 1
4 157293 157294
3 81666 81668 13806851267434892022
2 116280 116281 1
1 163245 163247 1
3 289833 289835 244401869236287882
3 135164 135164 8097051466237243604
1 113225 113226 1
4 43898 43900
4 289121 289121
2 133889 1...

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
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
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
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
0
0
0
...

result:

ok 72459 tokens

Test #20:

score: 0
Accepted
time: 517ms
memory: 158116kb

input:

290000 290000
4 130502 130504
2 15321 15322 1
3 275364 275364 4162744751939177223
4 99544 99545
4 100620 100621
3 193438 193439 13148803698890728003
2 125274 125275 1
2 241880 241882 1
3 168292 168292 2833035078327940594
3 27814 27816 10620786078931893277
4 136822 136823
3 56337 56338 74789752446323...

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
0
15159374354299362052
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
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
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...

result:

ok 72567 tokens

Subtask #3:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #21:

score: 0
Wrong Answer
time: 767ms
memory: 159508kb

input:

300000 300000
3 19765 150566 5167493634543664094
2 118662 201848 4
4 127772 255639
1 363 249365 3
3 11598 175102 16530837351901358978
4 36444 234550
2 60767 191641 3
3 76143 190023 11283165360234648940
4 151255 257891
3 69394 97478 6131272952305682140
1 45277 77429 3
2 6151 122134 2
4 48165 93810
4 ...

output:

10556488787335954570
18212772968701168848
11437199959288606460
8399299997760384588
11718115706414345024
10430039748605185716
10791380095122215184
15944361710687625976
16135961443839657432
4434563019586156035
8749535087882211887
14176305221399051252
13418003553475512102
1702668605387454355
8261145120...

result:

wrong answer 35th words differ - expected: '17195564649549599964', found: '6068038867674916171'

Subtask #4:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 639ms
memory: 177216kb

input:

300000 300000
1 85444 86076 59
1 41150 41411 71
1 278698 279414 45
1 238445 239202 56
1 29965 29984 49
1 282953 283272 37
1 34668 35653 86
2 198587 198744 28
1 270855 271611 58
1 2130 2965 773
1 161601 162298 937
1 50299 50435 36
1 100759 101198 64
1 120208 120543 84
1 295293 295732 34
1 112185 1129...

output:

0
0
18162310077274802299
3186549172621019845
1015322812354713049
0
8905950571534092377
11348826362833966042
0
11383692184766570780
0
0
0
5040988162175396331
0
0
6516829787016916659
0
0
0
0
0
11111222643446590724
13538200113619418676
0
3861451384001627672
0
8966140148489183762
8492609762179423852
0
1...

result:

wrong answer 3rd words differ - expected: '16968625150574630951', found: '18162310077274802299'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%