QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#872140#8618. Have You Seen This Subarray?ucup-team139#WA 3ms35584kbC++233.1kb2025-01-25 23:44:542025-01-25 23:45:02

Judging History

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

  • [2025-01-25 23:45:02]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:35584kb
  • [2025-01-25 23:44:54]
  • 提交

answer

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#include <climits>
#include <iomanip>
using namespace std;

#define int int64_t
using namespace std;
int base = 100003;

vector<int> lar(vector<int> &v, int i, int s)
{
  vector<int> res;
  for (int j = max(int(0), i - s + 1); j <= min(i, (int)v.size() - s); ++j)
  {
    int ans = 0;
    bool inc = 1;
    for (int k = j; k < j + s; ++k)
      ans = ans * base + v[k];
    for (int k = j + 1; k < j + s; ++k)
      if (v[k] - v[k - 1] != 1)
        inc = 0;
    if (!inc)
      res.push_back(ans);
  }
  return res;
}
vector<int> larii(vector<int> &v, int i1, int i2, int s)
{
  vector<int> r1 = lar(v, i1, s);
  vector<int> r2 = lar(v, i2, s);
  for (int i = 0; i < (int)r2.size(); ++i)
    r1.push_back(r2[i]);
  return r1;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, _m, q;
  cin >> n >> _m >> q;

  if (n <= 100)
  {
    const int MAXM = 100'001;
    vector ds(n + 1, vector(n + 1, bitset<MAXM>()));

    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
      a[i] = i;

    auto upd = [&](int t)
    {
      for (int i = 1; i + 1 <= n; i++)
      {
        ds[a[i]][a[i + 1]][t] = true;
      }
    };

    upd(0);
    for (int i = 1; i <= _m; i++)
    {
      int x, y;
      cin >> x >> y;
      swap(a[x], a[y]);
      upd(i);
    }

    for (int i = 0; i < q; i++)
    {
      int k;
      cin >> k;
      vector<int> b(k);
      for (auto &j : b)
        cin >> j;

      bitset<MAXM> ans;
      ans = ~ans;
      for (int j = 0; j + 1 < k; j++)
      {
        ans &= ds[b[j]][b[j + 1]];
      }
      cout << ans._Find_first() << "\n";
    }

    return 0;
  }

  vector<int> v(n);
  for (int i = 0; i < n; ++i)
    v[i] = i + 1;
  array<map<int, int>, 5> m;
  for (int i = 1; i <= _m; ++i)
  {
    int i1, i2;
    cin >> i1 >> i2;
    --i1;
    --i2;
    swap(v[i1], v[i2]);
    for (int s = 0; s < 5; ++s)
      for (auto x : larii(v, i1, i2, s + 1))
        if (!m[s].count(x))
          m[s][x] = i;
  }
  for (int _ = 0; _ < q; ++_)
  {
    int bl;
    cin >> bl;
    vector<int> b(bl);
    for (auto &o : b)
      cin >> o;
    int ans = 0;
    for (int i = 0; i < bl; ++i)
    {
      int s = min(int(4), (int)b.size());
      if (i + s < bl)
      {
        int as = 0;
        for (int j = i; j <= i + s; ++j)
          as = as * base + b[j];
        if (m[s].count(as))
          ans = max(ans, m[s][as]);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 35584kb

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: -100
Wrong Answer
time: 3ms
memory: 4608kb

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:

0
0
0
0
391
0
0
443
216
0
0
420
0
0
434
0
163
0
0
122
0
0
0
0
285
0
0
0
0
0
0
0
0
0
0
0
0
0
0
25
0
0
0
0
0
0
374
0
226
0
0
0
0
0
0
0
0
0
333
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
284
0
107
0
0
0
0
0
0
0
0
82
0
0
0
285
213
177
0
0
0
0
0
0
0
0
70
0
0
0
0
0
169
0
0
0
0
0
166
255
0
0
0
0
40
0
...

result:

wrong answer 1st numbers differ - expected: '68', found: '0'