UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#203371#3561. 暖雨晴风初破冻yllcm1009640ms3576kbC++114.5kb2024-02-24 09:29:322024-02-24 13:00:59

answer

/*
author:yllcm
link:https://loj.ac/s/1973855
*/
#include<bits/stdc++.h>
#define ll long long
#define db double
#define ull unsigned long long
#define pb push_back
#define pii pair<int, int>
#define FR first
#define SE second
#define int long long
using namespace std;
inline int read() {
  int x = 0; bool op = false;
  char c = getchar();
  while(!isdigit(c))op |= (c == '-'), c = getchar();
  while(isdigit(c))x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return op ? -x : x;
}
const int N = 1e5 + 10;
int n, Q;
int a[N];
struct Block {
  int B, T;
  int cnt[N], L[N], R[N], pos[N], sum[N], ts[N], vis[N];
  void build() {
    B = sqrt(n);
    for(int i = 1; i <= n; i += B) {
      L[++T] = i; R[T] = min(n, i + B - 1);
      for(int j = L[T]; j <= R[T]; j++)
        sum[pos[j] = T] += a[j], cnt[T]++;
    }
    return ;
  }
  void ins(int x, int w) {
    cnt[pos[x]] -= w; vis[x] += w;
    if(w == 1)sum[pos[x]] -= a[x] + ts[pos[x]], a[x] = 0;
    else a[x] = -ts[pos[x]];
    // cout << x << ' ' << w << ' ' << a[x] + ts[pos[x]] << endl;
    return ;
  }
  void pushdown(int x) {
    for(int i = L[x]; i <= R[x]; i++)if(!vis[i])a[i] += ts[x];
    ts[x] = 0;
    return ;
  }
  void update(int l, int r, int w) {
    int bl = pos[l], br = pos[r];
    if(bl == br) {
      pushdown(bl);
      for(int i = l; i <= r; i++)if(!vis[i])a[i] += w, sum[bl] += w;
      return ;
    }
    pushdown(bl); pushdown(br);
    for(int i = l; i <= R[bl]; i++)if(!vis[i])a[i] += w, sum[bl] += w;
    for(int i = L[br]; i <= r; i++)if(!vis[i])a[i] += w, sum[br] += w;
    for(int i = bl + 1; i < br; i++)sum[i] += cnt[i] * w, ts[i] += w;
    return ;
  }
  int query(int l, int r) {
    int bl = pos[l], br = pos[r], res = 0;
    if(bl == br) {
      pushdown(bl);
      for(int i = l; i <= r; i++)if(!vis[i])res += a[i] + ts[bl];
      return res;
    }
    pushdown(bl); pushdown(br);
    for(int i = l; i <= R[bl]; i++)if(!vis[i])res += a[i] + ts[bl];
    for(int i = L[br]; i <= r; i++)if(!vis[i])res += a[i] + ts[br];
    // cout << "qyr:" << l << ' ' << r << endl;
    // for(int i = l; i <= R[bl]; i++)cout << vis[i] << ' '; cout << endl;
    // for(int i = L[br]; i <= r; i++)cout << vis[i] << ' '; cout << endl;
    // for(int i = bl + 1; i < br; i++)cout << sum[i] << ' '; cout << endl;
    // cout << "q:" << bl << ' ' << br << ' ' << l << ' ' << r << ' ' << res << endl;
    for(int i = bl + 1; i < br; i++)res += sum[i];
    return res;
  }
}bl;
struct Fire {
  vector<pii> fi;
  void ins(int x) {
    vector<pii> nfi;
    for(auto t : fi)if(x >= t.FR && x <= t.SE)return ;
    int flg = 0;
    for(auto t : fi) {
      if(t.FR > x && !flg)nfi.pb({x, x}), flg = 1;
      nfi.pb(t);
    }
    if(!flg)nfi.pb({x, x});
    swap(fi, nfi);
    bl.ins(x, 1);
    return ;
  }
  void del(int l, int r) {
    vector<pii> nfi;
    for(auto t : fi) {
      int tl = max(l, t.FR), tr = min(r, t.SE);
      if(tl > tr) {nfi.pb(t); continue;}
      for(int j = tl; j <= tr; j++)bl.ins(j, -1);
      // cout << l << ' ' << r << endl;
      if(tl == t.FR && tr == t.SE)continue;
      if(tl > t.FR && tr < t.SE)nfi.pb({t.FR, tl - 1}), nfi.pb({tr + 1, t.SE});
      else nfi.pb(tl > t.FR ? (pii){t.FR, tl - 1} : (pii){tr + 1, t.SE});
    }
    swap(fi, nfi);
    return ;
  }
  void grow() {
    vector<pii> nfi;
    for(auto t : fi) {
      if(nfi.size() && nfi.back().SE >= t.FR - 1) {
        nfi.back().SE = min(n, t.SE + 1);
        if(t.SE < n && !bl.vis[t.SE + 1])bl.ins(t.SE + 1, 1);
      }
      else {
        pii tmp(max(1ll, t.FR - 1), min(n, t.SE + 1));
        // cout << "grow:" << t.FR << ' ' << t.SE << endl;
        if(t.FR > 1 && !bl.vis[t.FR - 1])bl.ins(t.FR - 1, 1);
        if(t.SE < n && !bl.vis[t.SE + 1])bl.ins(t.SE + 1, 1);
        nfi.pb(tmp);
      }
    }
    swap(fi, nfi);
    return ;
  }
  void debug() {
    cout << "debug\n";
    for(auto t : fi)printf("%d %d\n", t.FR, t.SE);
    return ;
  } 
}fire;
signed main() {
  n = read(); Q = read();
  for(int i = 1; i <= n; i++)a[i] = read();
  bl.build();
  while(Q--) {
    int op = read();
    if(op == 1) {
      int l = read(), r = read(), k = read();
      bl.update(l, r, k);
    }
    else if(op == 2) {
      int l = read(), r = read();
      printf("%lld\n", bl.query(l, r));
    }
    else if(op == 3) {
      int pos = read();
      fire.ins(pos);
    }
    else if(op == 4) {
      int l = read(), r = read();
      fire.del(l, r);
    }
    fire.grow();
  }
  return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

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

input:

1000 1000
81 994 221 451 394 449 476 558 407 615 761 602 503 465 230 906 931 113 730 582 259 250 437...

output:

156069
483845
460280
418778
456795
244196
485463
728575
300633
26924
392326
827853
2020
965122
94947...

result:

ok 402 numbers

Test #2:

score: 30
Accepted
time: 126ms
memory: 3568kb

input:

100000 100000
2391 79276 25045 80660 77319 81929 5968 97143 82519 13216 44143 87115 16988 9031 49435...

output:

3599824742
2757580462
516973850
4977737504
3283633693
263148086
2683965141
322825304
98228500
159960...

result:

ok 49880 numbers

Test #3:

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

input:

50000 50000
11001 19616 26153 31771 9191 2530 14460 21174 21845 25613 6227 48587 39811 11234 10754 1...

output:

510862005
959233742
708288294
129793918
580368020
112678734
5077836052
1379979005
2466639605
3670309...

result:

ok 12497 numbers

Test #4:

score: 10
Accepted
time: 78ms
memory: 2404kb

input:

50000 50000
2360 10685 40370 35453 24707 3218 17886 27818 21222 4771 42826 35509 26444 4437 521 3568...

output:

780345356
939050473
1283948463
1046717025
242206179
1243867193
178854865
1416880878
143115338
308137...

result:

ok 11230 numbers

Test #5:

score: 10
Accepted
time: 67ms
memory: 2404kb

input:

50000 50000
772 26804 2901 34327 36617 36693 49145 23580 32815 40080 36236 40727 30212 25609 14581 1...

output:

265940613
877470897
1089117192
1226404086
316563196
164065329
18828287
607711789
2361083625
17510647...

result:

ok 11276 numbers

Test #6:

score: 3
Accepted
time: 1094ms
memory: 3576kb

input:

100000 500000
23598 59134 8863 60886 21829 82373 74110 48795 30203 25691 80620 66290 51053 38802 625...

output:

2599938966
3494173602
20803288326
11852440378
9690985112
17408896416
20329223297
16721521078
4326318...

result:

ok 112080 numbers

Test #7:

score: 3
Accepted
time: 1129ms
memory: 3572kb

input:

100000 500000
83200 76760 65391 99017 64340 34208 73413 70061 75768 47198 46032 67060 6951 91391 452...

output:

391305538
201977739
6569115874
2744407544
2250341095
6293073851
5290061700
1379250292
3267405072
121...

result:

ok 111728 numbers

Test #8:

score: 3
Accepted
time: 1185ms
memory: 3576kb

input:

100000 500000
39468 31280 53315 84724 92621 57923 49180 9691 15432 16302 78194 18964 15520 33979 881...

output:

2664236833
2142453334
3344202426
6080732699
7570499379
7174605284
2915246437
3881990232
5025551150
3...

result:

ok 112122 numbers

Test #9:

score: 3
Accepted
time: 905ms
memory: 3576kb

input:

100000 500000
91096 60044 83673 92029 60347 18901 9369 4559 69072 2133 14684 16602 51164 19893 8334 ...

output:

1726324881
8995064263
3219827471
2143916812
5226011396
2435821729
7760003896
9549382195
26528706862
...

result:

ok 112488 numbers

Test #10:

score: 3
Accepted
time: 776ms
memory: 3576kb

input:

100000 499999
9065 58203 42984 96443 13951 75821 78588 39422 52322 71483 41158 60185 71584 56357 687...

output:

32388372
5006251604
606774714
2569696249
4403446148
9173575725
6374151559
1624248909
4499341490
8156...

result:

ok 112505 numbers

Test #11:

score: 3
Accepted
time: 637ms
memory: 3572kb

input:

100000 499999
50524 60340 70219 26891 97835 13177 68104 86941 54924 71114 25814 15067 82900 24067 18...

output:

1644635808
11382744280
12831477953
14485840042
16820423325
19546542227
4107669100
9306403402
1387985...

result:

ok 101559 numbers

Test #12:

score: 3
Accepted
time: 948ms
memory: 3572kb

input:

100000 499999
33701 27491 15343 88962 42881 47656 7072 11014 5278 22740 41852 62150 37726 15216 8565...

output:

2750462427
813440130
8187150828
289640115
5224985066
9867424963
12892099488
8600450305
7586166393
24...

result:

ok 99796 numbers

Test #13:

score: 3
Accepted
time: 902ms
memory: 3576kb

input:

100000 499999
19190 38143 19083 6016 86066 64974 29130 57497 91109 41628 13200 37970 39097 30244 992...

output:

1945237740
2863008530
4151469737
4830924602
5818425256
490031695
1180065329
1366975602
2408496159
75...

result:

ok 66989 numbers

Test #14:

score: 3
Accepted
time: 1042ms
memory: 3572kb

input:

100000 499999
89883 41668 81840 39872 15443 12467 7644 99594 10092 5538 9171 78035 50965 94281 29658...

output:

920051043
2957788038
454252013
3885894682
1705725453
2090599677
4916307749
6088123883
9716834917
173...

result:

ok 146482 numbers

Test #15:

score: 3
Accepted
time: 653ms
memory: 3568kb

input:

100000 499999
94310 9211 33496 80265 55492 71959 99190 10977 43911 14207 31193 2268 88465 44017 9258...

output:

453017333
2031258281
2584278804
3770189255
170266243
5082023712
7180579267
10913542201
14499486974
9...

result:

ok 244984 numbers

Extra Test:

score: 0
Extra Test Passed