QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#869583#8618. Have You Seen This Subarray?ucup-team896#WA 160ms12764kbC++204.2kb2025-01-25 11:33:142025-01-25 11:33:15

Judging History

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

  • [2025-01-25 11:33:15]
  • 评测
  • 测评结果:WA
  • 用时:160ms
  • 内存:12764kb
  • [2025-01-25 11:33:14]
  • 提交

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> void chkmn(T &x, T y) { if (y < x) x = y; }
template<class T> void chkmx(T &x, T y) { if (y > x) x = y; }

using namespace std;

const int mod = 1011451423;

inline void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
inline int Add(int x, int y) { x += y; if (x >= mod) x -= mod; return x; }
inline int Sub(int x, int y) { x -= y; if (x < 0) x += mod; return x; }

const int maxn = 100010;
const int base = 133331;

int n, m, q, sz, tot, ct, ans[maxn], a[maxn], w[maxn], pw[maxn], t[maxn << 2], p[maxn], len[maxn], need[maxn];
pii opt[maxn];
pair<int, pii> js[maxn];
map<pii, vector<int>> que2;
vector<pii> que[maxn];

#define mid ((l + r) >> 1)

void build(int c, int l, int r) {
  if (l == r) return t[c] = l, void();
  build(c << 1, l, mid), build(c << 1 | 1, mid + 1, r);
  t[c] = Add(1ll * t[c << 1] * pw[r - mid] % mod, t[c << 1 | 1]);
}

void upd(int c, int l, int r, int x, int v) {
  if (l == r) return t[c] = v, void();
  if (x <= mid) upd(c << 1, l, mid, x, v);
  else upd(c << 1 | 1, mid + 1, r, x, v);
  t[c] = Add(1ll * t[c << 1] * pw[r - mid] % mod, t[c << 1 | 1]);
}

int qry(int c, int l, int r, int x, int y) {
  if (l == x && r == y) return t[c];
  if (y <= mid) return qry(c << 1, l, mid, x, y);
  else if (x > mid) return qry(c << 1 | 1, mid + 1, r, x, y);
  else return Add(1ll * qry(c << 1, l, mid, x, mid) * pw[y - mid] % mod, qry(c << 1 | 1, mid + 1, r, mid + 1, y));
}

#undef mid

void check(int d, int o) {
  int val = 0;
  rep (k, 0, 2) val = Add(1ll * val * base % mod, p[d + k]);
  int id = lower_bound(w + 1, w + tot + 1, val) - w;
  if (w[id] != val) return;
  vector<pii> nxt;
  for (auto [x, s] : que[id]) {
    int L = d - s + 1, R = L + len[x] - 1;
    if (L >= 1 && R <= n && need[x] == qry(1, 1, n, L, R)) ans[x] = o;
    else nxt.emplace_back(x, s);
  }
  que[id] = nxt;
}

int main() {
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  cin >> n >> m >> q;
  pw[0] = 1;
  rep (i, 1, n) pw[i] = 1ll * pw[i - 1] * base % mod;
  rep (i, 1, m) cin >> opt[i].fi >> opt[i].se;
  rep (i, 1, q) {
    cin >> sz, len[i] = sz;
    rep (j, 1, sz) cin >> a[j];
    int ok = 1;
    rep (j, 1, sz - 1) ok &= (a[j + 1] == a[j] + 1);
    if (!ok) {
      ans[i] = m + 1;
      if (sz == 2) {
        que2[pii(a[1], a[2])].emplace_back(i);
      } else {
        rep (j, 1, sz - 2) {
          int val = 0;
          rep (k, 0, 2) val = Add(1ll * val * base % mod, a[j + k]);
          js[++tot] = make_pair(val, pii(i, j));
        }
        need[i] = 0;
        rep (j, 1, sz) need[i] = Add(1ll * need[i] * base % mod, a[j]);
      }
    }
  }
  sort(js + 1, js + tot + 1), ct = tot, tot = 0;
  rep (i, 1, ct) if (i == 1 || js[i].fi != js[i - 1].fi) w[++tot] = js[i].fi;
  rep (i, 1, ct) que[lower_bound(w + 1, w + tot + 1, js[i].fi) - w].emplace_back(js[i].se);
  build(1, 1, n);
  rep (i, 1, n) p[i] = i;
  rep (i, 1, m) {
    auto [x, y] = opt[i];
    upd(1, 1, n, x, p[y]), upd(1, 1, n, y, p[x]), swap(p[x], p[y]);
    if (x > 1 && que2.count(pii(p[x - 1], p[x]))) {
      for (int id : que2[pii(p[x - 1], p[x])]) ans[id] = i;
      que2.erase(pii(p[x - 1], p[x]));
    }
    if (y > 1 && que2.count(pii(p[y - 1], p[y]))) {
      for (int id : que2[pii(p[y - 1], p[y])]) ans[id] = i;
      que2.erase(pii(p[y - 1], p[y]));
    }
    if (x < n && que2.count(pii(p[x], p[x + 1]))) {
      for (int id : que2[pii(p[x], p[x + 1])]) ans[id] = i;
      que2.erase(pii(p[x], p[x + 1]));
    }
    if (y < n && que2.count(pii(p[y], p[y + 1]))) {
      for (int id : que2[pii(p[y], p[y + 1])]) ans[id] = i;
      que2.erase(pii(p[y], p[y + 1]));
    }
    rep (d, x - 2, x) if (d >= 1 && d + 2 <= n) check(d, i);
    rep (d, y - 2, y) if (d >= 1 && d + 2 <= n) check(d, i);
  }
  rep (i, 1, q) cout << ans[i] << '\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 12004kb

input:

6 3 5
1 5
3 4
1 6
2 4 1
3 3 1 5
3 3 4 5
4 5 2 4 3
2 6 2

output:

1
3
0
2
3

result:

ok 5 number(s): "1 3 0 2 3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 9888kb

input:

50 50 16
21 30
14 39
5 32
31 48
38 50
40 49
14 33
32 42
7 15
5 25
24 28
8 10
18 24
5 39
4 37
9 28
29 39
2 35
11 32
48 49
12 17
38 44
26 33
12 40
19 49
40 41
17 18
20 30
11 15
21 36
37 38
7 48
17 21
8 38
30 34
3 31
7 12
31 47
2 37
20 41
13 40
33 39
10 49
19 40
12 30
23 28
9 45
27 32
4 37
27 29
2 44 4...

output:

0
29
44
22
23
18
1
37
3
16
0
16
0
13
0
0

result:

ok 16 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 9788kb

input:

500 500 165
5 424
246 385
355 428
43 338
214 378
286 469
6 467
149 333
203 411
7 111
395 483
256 288
69 414
33 429
159 425
22 470
13 425
235 292
291 412
76 224
64 207
198 365
268 314
116 366
338 386
58 265
328 330
146 493
89 288
120 465
187 201
336 499
406 485
195 406
56 485
410 424
125 149
154 216
...

output:

68
77
385
0
391
119
0
443
216
0
0
420
0
136
434
0
163
77
410
122
0
0
436
474
285
0
109
89
13
0
38
0
0
133
48
390
0
0
157
25
402
0
232
272
0
0
374
294
226
0
16
0
151
295
80
17
184
379
333
199
431
0
0
0
10
0
0
0
357
431
165
0
0
408
296
0
0
0
191
0
275
233
184
284
0
107
0
213
193
317
0
0
349
311
82
0
1...

result:

ok 165 numbers

Test #4:

score: 0
Accepted
time: 6ms
memory: 10016kb

input:

5000 5000 188
121 3352
1927 3462
1474 2956
818 3688
2965 3432
2063 2891
946 2028
2270 3486
1809 2413
108 4387
920 4467
198 2766
2950 4940
1447 1580
4703 4722
1285 1768
94 1205
1863 4496
908 4980
2181 3000
1508 3798
2161 4451
952 3285
339 1166
291 3872
3014 4857
1999 2809
2892 4392
1994 3280
557 3600...

output:

619
2857
3580
3942
3094
189
0
3024
3750
3954
51
3815
1731
150
3082
4683
4303
2289
153
629
1512
1245
1028
4033
1158
1279
3758
1929
3077
2317
4291
632
2855
1513
526
1047
675
278
498
1535
2549
2361
3393
4438
458
1618
158
3991
2120
3290
2469
2357
3152
3166
206
2279
2352
3077
4786
0
2682
2822
2598
3157
4...

result:

ok 188 numbers

Test #5:

score: -100
Wrong Answer
time: 160ms
memory: 12764kb

input:

100000 100000 33297
71020 88781
73567 91865
28411 98582
30528 55399
32377 88782
5464 33315
16441 21471
13984 59425
4953 40519
24887 54173
42736 94259
36960 89613
25476 27783
95468 96479
72650 76406
8812 58175
71657 81205
24702 49487
50388 67643
6272 23503
25087 72725
48821 81737
30758 71554
55829 82...

output:

27228
22301
7931
0
75416
1215
0
25576
22641
0
0
17383
24756
30126
15021
32805
65792
88809
22668
0
0
0
0
9889
0
53443
65387
0
80361
74814
86721
0
0
63844
0
33458
19889
75869
79460
33108
72549
68381
3025
0
0
25883
20179
55587
47021
84515
0
33494
15631
0
62931
0
53663
44093
21837
40160
26104
55703
0
0
...

result:

wrong answer 4791st numbers differ - expected: '74060', found: '71458'