QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#418682#8718. 保区间最小值一次回归问题wsyearAC ✓984ms138772kbC++172.8kb2024-05-23 15:07:152024-05-23 15:07:15

Judging History

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

  • [2024-05-23 15:07:15]
  • 评测
  • 测评结果:AC
  • 用时:984ms
  • 内存:138772kb
  • [2024-05-23 15:07:15]
  • 提交

answer

#include <bits/stdc++.h>

#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

template<class T>inline void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T>inline void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

const int maxn = 500010;
const int inf = 2e9;

int n, m, tot, a[maxn], mx[maxn], st[maxn][20], c[maxn], tlim[maxn], val[maxn];
ll dp[maxn];
vector<int> mvec[maxn], pos[maxn];
vector<pii> vec[maxn];
tuple<int, int, int> lim[maxn];
multiset<int> S;

int que(int l, int r) {
  int k = __lg(r - l + 1);
  return min(st[l][k], st[r - (1 << k) + 1][k]);
}

void work() {
  cin >> n >> m;
  rep (i, 1, n) cin >> a[i];
  rep (i, 1, n) mvec[i].clear();
  rep (i, 1, m) {
    int l, r, v;
    cin >> l >> r >> v, c[i] = v;
    mvec[l].emplace_back(v);
    mvec[r + 1].emplace_back(-v);
    lim[i] = make_tuple(l, r, v);
  }
  S.clear();
  rep (i, 1, n) {
    for (int x : mvec[i]) {
      if (x > 0) S.emplace(x);
      else S.erase(S.find(-x));
    }
    if (S.empty()) mx[i] = st[i][0] = inf;
    else mx[i] = st[i][0] = *prev(S.end());
  }
  rep (j, 1, 19) rep (i, 1, n - (1 << j) + 1) {
    st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
  }
  rep (i, 1, m) {
    auto [l, r, v] = lim[i];
    if (que(l, r) != v) return cout << "-1\n", void();
  }
  sort(c + 1, c + m + 1), tot = unique(c + 1, c + m + 1) - c - 1;
  rep (i, 1, tot) vec[i].clear(), pos[i].clear();
  ll ans = 0;
  rep (i, 1, n) if (mx[i] != inf) {
    if (a[i] < mx[i]) ans += mx[i] - a[i], a[i] = mx[i];
    int w = lower_bound(c + 1, c + tot + 1, mx[i]) - c;
    pos[w].emplace_back(i);
  }
  rep (i, 1, m) {
    auto [l, r, v] = lim[i];
    v = lower_bound(c + 1, c + tot + 1, v) - c;
    vec[v].emplace_back(l, r);
  }
  rep (i, 1, tot) if (SZ(vec[i])) {
    int w = SZ(pos[i]);
    rep (j, 1, w) val[j] = a[pos[i][j - 1]] - c[i];
    val[w + 1] = 0;
    rep (j, 1, w + 1) tlim[j] = 0;
    for (auto &[l, r] : vec[i]) {
      l = lower_bound(ALL(pos[i]), l) - pos[i].begin() + 1;
      r = upper_bound(ALL(pos[i]), r) - pos[i].begin();
      chkmx(tlim[r + 1], l);
    }
    rep (j, 1, w + 1) chkmx(tlim[j], tlim[j - 1]);
    rep (j, 1, w + 1) dp[j] = 1e18;
    multiset<ll> S;
    int pos = 0;
    S.emplace(0);
    rep (j, 1, w + 1) {
      while (pos < tlim[j]) {
        S.erase(S.find(dp[pos]));
        pos++;
      }
      dp[j] = *S.begin() + val[j];
      S.emplace(dp[j]);
    }
    ans += dp[w + 1];
  }
  cout << ans << '\n';
}

int main() {
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  int t; cin >> t;
  while (t--) work();
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 38724kb

input:

1
3 2
2023 40 41
1 1 2022
2 3 39

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 863ms
memory: 118648kb

input:

1000
100 100
1 35141686 84105222 84105220 7273527 178494861 178494861 112519027 77833654 77833656 261586535 278472336 278472336 261586536 416361017 416361017 426649080 323519513 278472337 420127821 420127823 420127823 482516531 434108818 420127821 631535744 615930922 546346921 546346920 546346920 70...

output:

49
46
43
39
48
47
49
46
46
48
47
56
952
53
50
55
46
62
57
46
49
50
42
55
51
57
50
43
41
44
41
53
57
45
59
45
48
44
37
48
43
52
46
50
909
948
48
50
50
50
45
42
54
53
42
46
55
52
51
48
38
48
43
41
55
41
48
47
38
51
54
46
44
47
46
49
43
48
42
45
47
36
43
45
53
46
48
45
42
45
48
40
49
54
44
43
45
48
49
...

result:

ok 1000 numbers

Test #3:

score: 0
Accepted
time: 901ms
memory: 118672kb

input:

1000
100 100
40 35141748 84105257 84105343 7273633 178494885 178495007 112519027 77833696 77833671 261586538 278472335 278472427 261586652 416361094 416361130 426649132 323519561 278472520 420127898 420127936 420127900 482516532 434108895 420127875 631535939 615931040 546346933 546346951 546347103 7...

output:

5391
5728
5395
4133
4671
3496
3629
5091
5285
5530
4748
5441
84743
6061
4524
6175
5755
5357
3835
5486
4698
5872
4955
5320
4374
5628
4426
4747
5019
4439
4361
5774
6141
6897
5578
5067
5036
5719
4380
4763
4098
4693
4514
5690
92018
84532
4776
5056
4351
5501
4885
4828
5223
6395
3673
6007
6028
5993
5289
45...

result:

ok 1000 numbers

Test #4:

score: 0
Accepted
time: 922ms
memory: 118736kb

input:

1000
100 100
148088468 98149781 583014390 471155624 805747464 361353765 809227446 405213819 979246312 746234854 328924822 293996764 439427756 927284157 709886804 719570910 987283502 607077506 460561747 601690465 661900658 689494603 664094557 738719400 968257412 849232761 704892887 981300891 63494525...

output:

13272909075
10500705683
12729662919
9598250477
14090962014
12379912845
12111344391
11664729042
11963959801
12049221193
11907426860
12443185625
241361559829
15859152345
12213559141
13098156239
16019877206
13030210346
11413013605
12943939894
15243504691
10167904190
13684987690
12625876652
13823026696
...

result:

ok 1000 numbers

Test #5:

score: 0
Accepted
time: 7ms
memory: 39080kb

input:

1000
5 4
2 4 4 3 6
1 5 5
3 4 4
3 3 3
1 2 2
3 1
5 1 5
2 3 6
1 6
1
1 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
2
0
7
-1
2
-1
-1
2
0
-1
4
-1
-1
3
4
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
6
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
-1
-1
-1
-1
0
-1
-1
6
-1
-1
3
12
3
-1
-1
2
5
-1
...

result:

ok 1000 numbers

Test #7:

score: 0
Accepted
time: 3ms
memory: 39076kb

input:

1000
2 4
2 5
1 2 5
2 2 2
1 2 3
1 1 4
2 6
1 2
2 2 3
1 2 2
1 2 2
1 2 1
2 2 5
2 2 1
5 6
1 5 6 3 2
1 3 5
4 4 3
2 5 4
3 4 4
3 4 6
3 5 4
1 5
4
1 1 4
1 1 1
1 1 5
1 1 6
1 1 5
3 6
4 4 3
3 3 1
1 3 5
1 2 4
1 2 1
1 1 5
3 3 5
3 5
4 6 1
1 3 4
1 1 2
3 3 2
2 3 3
2 3 6
4 4
5 2 2 5
1 2 3
4 4 2
3 4 2
1 4 6
2 3
2 4
1 2...

output:

-1
-1
-1
-1
-1
-1
-1
-1
3
6
0
-1
-1
-1
3
-1
-1
-1
-1
-1
4
-1
-1
-1
-1
-1
-1
2
4
15
-1
-1
1
-1
-1
0
-1
-1
-1
10
-1
-1
-1
-1
-1
-1
-1
-1
6
-1
-1
-1
3
-1
-1
-1
-1
-1
-1
-1
-1
6
-1
-1
-1
-1
14
-1
4
-1
-1
-1
-1
5
1
-1
-1
-1
3
-1
-1
-1
-1
-1
-1
-1
2
-1
-1
-1
1
-1
-1
-1
-1
3
-1
0
-1
-1
-1
4
-1
-1
-1
-1
-1
...

result:

ok 1000 numbers

Test #8:

score: 0
Accepted
time: 923ms
memory: 119856kb

input:

1000
100 100
781659836 728394474 976072309 892982594 984461294 544357318 272504583 429726611 929869328 165593135 780537409 388550208 394106952 536386495 178682760 547490556 415752713 413623503 493296569 744570545 678280769 885687637 835319992 840071843 408228451 781310602 540636792 774246539 6120628...

output:

12705433408
55120033165837
13450258183
12735860443
11247877676
13939137030
12829445572
11574137865
11398808540
10697262762
13371010658
17258148491
16226464358
13897969840
15446107235
16212563843
12247652408
15352057207
14132651030
14226302785
13635621595
13689774675
11319898570
12683442363
902428534...

result:

ok 1000 numbers

Test #9:

score: 0
Accepted
time: 954ms
memory: 118844kb

input:

1000
2000 1141
929561418 449354985 881596928 339908475 381312783 866123819 740424342 565164163 920078862 621669462 436387841 878801388 720806069 460686281 657600480 981836697 309520504 864126423 538867850 248549332 892109348 890903917 752649234 749678128 581123944 623047728 836985413 566880975 59432...

output:

165420933213
12589548503
6726264286
17929568756
15494044403
16099615066
9783562265
13484879490
12984235550
13253784653
12809619989
12889073939
17918190063
281320331425
8099931090
12858519319
12312024494
14690241774
12389253869
12770602489
11442327026
10429814463
13569883942
14886708183
11159865597
1...

result:

ok 1000 numbers

Test #10:

score: 0
Accepted
time: 961ms
memory: 118580kb

input:

1000
2000 1141
2 1 313484123 304013173 9534484 9534484 227237070 227237069 227237070 227237070 227237070 687783316 427776542 227237069 227237070 358455992 227237069 227237068 227237068 227237070 518440217 775137168 227237069 599936591 358259977 358259978 358259977 227237069 227237070 227237070 22723...

output:

874
49
37
39
43
51
38
57
43
40
50
42
44
1058
45
56
47
53
49
44
50
44
47
48
38
48
56
52
48
43
53
49
41
48
50
49
57
44
43
987
37
40
42
55
30
55
57
53
50
50
37
44
54
53
53
43
48
57
54
47
53
45
39
53
44
48
56
49
54
55
56
-1
51
50
51
51
44
60
63
50
48
36
47
50
51
47
50
45
44
50
51
58
37
46
46
44
52
42
50...

result:

ok 1000 numbers

Test #11:

score: 0
Accepted
time: 984ms
memory: 119900kb

input:

1000
100 100
128230043 509596781 128230044 828409747 128230044 128230043 128230045 127019696 670097016 127019694 490051863 127019694 127019695 177747093 177747092 127019694 306342292 306342291 306342291 306342292 306342292 306342292 828409746 306342291 306342290 429863798 127019695 127019694 1401508...

output:

50
233597
40
48
53
52
47
52
51
39
48
50
48
55
48
51
44
50
49
46
42
45
48
49
49
51
43
46
51
50
39
50
56
48
33
41
45
51
49
49
52
47
44
644
38
51
45
43
38
50
43
38
51
42
958
49
47
54
45
42
50
47
48
40
45
48
49
53
47
46
37
40
47
43
50
54
45
40
48
37
47
50
51
46
53
971
49
48
59
39
52
45
37
47
54
49
54
39...

result:

ok 1000 numbers

Test #12:

score: 0
Accepted
time: 956ms
memory: 119904kb

input:

1000
100 100
128230081 509596798 128230064 828409762 128230074 128230055 128230089 127019734 670097053 127019738 490051894 127019712 127019731 177747109 177747100 127019698 306342304 306342301 306342298 306342320 306342326 306342307 828409748 306342296 306342325 429863807 127019738 127019745 1401508...

output:

1334
5078642
1186
943
1109
1552
859
1005
1396
786
1367
1241
1341
1442
1159
1239
1380
1519
1249
1083
1032
1138
1048
821
1221
1332
1309
974
865
971
1001
1140
1733
990
1030
982
999
1151
1020
902
1448
1111
1111
14656
1098
1263
1425
1200
1121
1190
975
1121
1175
999
21145
1123
1078
1401
1351
1229
1050
132...

result:

ok 1000 numbers

Test #13:

score: 0
Accepted
time: 917ms
memory: 119020kb

input:

1000
2000 1141
7 5 313484167 304013181 9534514 9534495 227237108 227237091 227237081 227237072 227237101 687783328 427776553 227237100 227237106 358456003 227237074 227237098 227237082 227237110 518440242 775137211 227237079 599936621 358259980 358260015 358260008 227237085 227237105 227237079 22723...

output:

15422
1156
1055
1453
1113
1312
1053
1385
1186
1147
1133
1015
1281
27883
1214
1390
1194
1138
1251
1263
1251
1044
1295
1057
938
1416
1505
1295
1372
1178
1234
1276
938
1041
1345
1849
1546
1064
1559
27273
1289
1238
1247
1480
1253
1570
1023
1414
1379
1172
838
1324
1283
1307
1092
1138
1383
1287
1377
1136
...

result:

ok 1000 numbers

Test #14:

score: 0
Accepted
time: 628ms
memory: 123332kb

input:

2
500000 299999
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...

output:

2999999997
0

result:

ok 2 number(s): "2999999997 0"

Test #15:

score: 0
Accepted
time: 585ms
memory: 138772kb

input:

2
500000 199999
999999999 999999998 999999997 999999996 999999995 999999994 999999993 999999992 999999991 999999990 999999989 999999988 999999987 999999986 999999985 999999984 999999983 999999982 999999981 999999980 999999979 999999978 999999977 999999976 999999975 999999974 999999973 999999972 9999...

output:

199958999500003
499999999500000

result:

ok 2 number(s): "199958999500003 499999999500000"

Extra Test:

score: 0
Extra Test Passed