QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#875359#2747. MeetingsWansur17 112ms196852kbC++202.6kb2025-01-29 16:38:142025-01-29 16:38:15

Judging History

This is the latest submission verdict.

  • [2025-01-29 16:38:15]
  • Judged
  • Verdict: 17
  • Time: 112ms
  • Memory: 196852kb
  • [2025-01-29 16:38:14]
  • Submitted

answer

#include "meetings.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 12;

ll sum[maxn];
ll a[maxn], pref[maxn];
int nxtl[maxn][21], nxtr[maxn][21];
int lg[maxn];
int n, m, k;

struct sparse {
   int mx[20][maxn];

   sparse() {
      for(int i = 0; i <= n; i++) {
         for(int k = 0; k < 20; k++) {
            mx[k][i] = 0;
         }
      }
   }

   void build(vector<int> a) {
      for(int i = 1; i <= n; i++) {
         mx[0][i] = a[i - 1];
         if(i > 1) lg[i] = lg[i / 2] + 1;
      }
      for(int k = 1; k < 20; k++) {
         for(int i = 1; i + (1 << k) - 1 <= n; i++) {
            mx[k][i] = max(mx[k - 1][i], mx[k - 1][i + (1 << (k - 1))]);
         }
      }
   }

   int get(int l, int r) {
      int k = lg[r - l + 1];
      return max(mx[k][l], mx[k][r - (1 << k) + 1]);
   }
} st[21], t;

int get(int l, int r, int lg, int rg) {
   int mx = t.get(l, r), ans = 0;
   int tl = l, tr = r;
   if(a[l] < mx) {
      tl = nxtr[l][mx];
      if(lg) ans = max(ans, get(l, tl - 1, 1, 0) + (mx - t.get(l, tl - 1)) * (tl - l));
   }
   if(a[r] < mx) {
      tr = nxtl[r][mx];
      if(rg) ans = max(ans, get(tr + 1, r, 0, 1) + (mx - t.get(tr + 1, r)) * (r - tr));
   }
   ans = max(ans, st[mx].get(tl, tr));
   return ans;
}

vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
   n = (int)H.size(), m = (int)L.size();
   for(int i = 1; i <= n; i++) {
      a[i] = H[i - 1];
      pref[i] = pref[i - 1] + a[i];
   }

   for(int i = 1; i <= n; i++) {
      for(int x = 1; x <= 20; x++) {
         nxtl[i][x] = nxtl[i - 1][x];
      }
      nxtl[i][a[i]] = i;
   }
   for(int x = 0; x <= 20; x++) {
      nxtr[n + 1][x] = n + 1;
   }
   for(int i = n; i; i--) {
      for(int x = 1; x <= 20; x++) {
         nxtr[i][x] = nxtr[i + 1][x];
      }
      nxtr[i][a[i]] = i;
   }
   t.build(H);
   for(int i = 1; i <= n; i++) {
      for(int x = 19; x >= 1; x--) {
         nxtl[i][x] = max(nxtl[i][x + 1], nxtl[i][x]);
         nxtr[i][x] = min(nxtr[i][x + 1], nxtr[i][x]);
      }
   }
   for(int k = 1; k <= 20; k++) {
      vector<int> v;
      for(int i = 1; i <= n; i++) {
         int val = 0;
         for(int x = 1; x < k; x++) {
            val += (k - x) * (nxtl[i][x] - nxtl[i][x + 1]);
            val += (k - x) * (nxtr[i][x + 1] - nxtr[i][x]);
         }
         v.push_back(val - (k - a[i]));
      }
      st[k].build(v);
   }

   vector<ll> ans(m);
   for(int i = 0; i < m; i++) {
      L[i]++, R[i]++;
      ans[i] = t.get(L[i], R[i]) * (R[i] - L[i] + 1) - get(L[i], R[i], 1, 1);
   }
   return ans;
}

詳細信息

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

1 1
877914575
0 0

output:

Unauthorized output

result:


Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 17
Accepted

Test #16:

score: 17
Accepted
time: 0ms
memory: 173916kb

input:

1 1
2
0 0

output:

2

result:

ok single line: '2'

Test #17:

score: 17
Accepted
time: 13ms
memory: 176216kb

input:

8014 48643
2 2 1 2 2 1 2 1 1 1 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 2 2 1 2 1 1 2 1 1 2 1 2 2 1 1 2 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 2 2 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 2 2 1 1 2 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 1 2 2 1 2 1 1 2 2 2 2 2 2 1 2 2 1 1 1 2 1 1 1 1 2 1 2 2 1 1 1 1 1 1 2...

output:

3556
2463
7389
1531
8055
565
9221
4957
4500
11001
4663
6013
10655
426
331
1495
3961
2197
3543
2786
773
13953
13077
6111
9863
7113
1576
12305
9019
9511
1019
10123
412
8015
13491
9367
7363
2001
5417
8827
361
815
5863
4607
173
6827
5345
5214
3430
2512
11655
3621
9051
290
583
4363
4694
2789
2865
613
464...

result:

ok 48643 lines

Test #18:

score: 17
Accepted
time: 78ms
memory: 196100kb

input:

100000 100000
1 2 1 1 2 1 1 2 2 2 2 1 1 1 2 2 1 1 2 2 2 1 1 2 2 1 2 2 1 2 2 1 1 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 1 1 2 2 1 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 2 2 2 1 1 1 1 2 2 2 1 1 2 1 1 1 1 2 2 2 1 1 1 2 2 2 1 1 2 2 1 2 ...

output:

168406
42134
67627
116194
47354
158012
95896
13652
69190
25189
58555
5891
39157
57985
58625
46834
7568
171074
30777
12773
22617
39621
135830
150402
35852
12238
23716
47584
40985
14212
52815
38157
143640
123162
99249
55757
19360
150426
73095
166458
841
90320
77842
10383
191290
20379
115790
134622
474...

result:

ok 100000 lines

Test #19:

score: 17
Accepted
time: 81ms
memory: 196548kb

input:

100000 100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

15743
57781
66106
101101
36861
31252
10449
79635
92420
165205
146533
139493
39521
12850
137807
41264
58619
114891
26922
158531
14672
75092
23640
50018
50006
6319
4579
2374
88970
185401
102244
57954
54048
62615
29866
85908
129018
82033
95840
26771
14103
53794
61872
1189
95090
36596
29519
38167
41533
...

result:

ok 100000 lines

Test #20:

score: 17
Accepted
time: 66ms
memory: 196852kb

input:

100000 100000
2 2 2 1 2 2 2 1 2 1 2 1 1 2 2 2 2 1 2 2 1 1 2 2 1 1 2 1 1 2 2 2 1 2 1 2 1 2 1 2 2 1 2 2 1 1 1 1 2 1 1 1 2 2 2 2 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 1 2 1 1 2 1 2 2 2 2 1 2 1 2 2 1 2 1 2 1 2 1 1 1 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 1 2 2 2 2 2 2 2 1 1 1 ...

output:

2
1
1
1
1
1
2
1
1
2
1
2
2
2
1
2
2
2
2
1
1
2
2
1
1
1
1
1
1
2
1
2
2
2
1
2
1
2
2
2
2
1
2
2
2
2
2
1
1
1
1
2
2
1
2
2
1
2
2
2
2
2
1
2
2
1
1
2
1
1
2
1
2
1
2
1
1
2
1
2
1
2
1
1
2
1
2
2
2
2
1
2
2
1
2
2
1
2
1
1
1
1
2
1
2
1
1
2
1
1
1
1
2
2
1
1
1
2
2
1
1
2
1
2
2
2
2
2
1
2
2
1
1
1
1
2
2
2
2
2
2
1
2
2
2
1
2
2
1
1
...

result:

ok 100000 lines

Test #21:

score: 17
Accepted
time: 75ms
memory: 196240kb

input:

100000 100000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

551
1102
1102
1102
619
551
551
784
1102
1102
898
1102
615
1102
1102
560
935
1102
1104
1102
1102
551
1102
551
1102
794
1102
765
551
1102
551
801
917
741
1102
1102
1102
1102
551
1047
726
748
1102
1102
551
660
551
1010
1102
551
1102
893
551
848
551
1102
551
1102
1102
551
1102
913
1013
733
575
1102
551
...

result:

ok 100000 lines

Test #22:

score: 17
Accepted
time: 73ms
memory: 196060kb

input:

100000 100000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...

output:

93072
10048
127454
7287
10697
48837
23960
38279
52605
83423
38556
45086
41906
74620
12478
24472
18593
338
86059
43004
26175
49213
6017
3782
50721
48508
59681
112042
7237
42567
103692
32514
64561
6857
34165
33644
80940
62943
82703
78504
93112
5189
23728
84158
128054
49624
15315
45684
55108
54868
5523...

result:

ok 100000 lines

Subtask #4:

score: 0
Wrong Answer

Dependency #3:

100%
Accepted

Test #23:

score: 0
Wrong Answer
time: 112ms
memory: 195896kb

input:

100000 100000
7 8 10 1 18 12 13 14 17 15 9 5 1 15 15 9 20 15 9 16 11 16 20 13 14 5 20 8 16 12 20 1 12 11 11 5 13 12 17 20 7 2 11 17 15 13 7 14 19 17 14 9 20 20 3 15 2 19 11 17 8 14 16 10 5 13 8 15 8 15 20 4 13 3 7 4 9 18 6 20 2 18 7 4 13 6 3 16 3 4 6 17 12 9 19 2 7 1 6 8 15 20 8 6 19 2 14 5 4 8 2 5 ...

output:

243321
699105
645251
998445
35782
1043118
796231
55270
240059
879491
37347
118783
585805
1554185
436421
496278
994351
188775
604898
1079211
449993
42631
1218305
878411
708938
147618
781638
46004
556585
763825
270450
1136151
761471
602651
419226
483635
288111
1675258
178643
1792498
68762
158291
15841...

result:

wrong answer 164th lines differ - expected: '902', found: '969'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%