# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
347404 | kingfran1907 | Matching (CEOI11_mat) | C++14 | 1331 ms | 46092 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long llint;
const int maxn = 1e6+10;
const int base = 101;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;
int n, m;
int a[maxn], b[maxn];
int tour[treesiz], cnt[treesiz], p[treesiz];
int pot[maxn];
vector< int > v;
int as[maxn];
int mul(int a, int b) {
llint out = (llint)a * b;
return out % mod;
}
void update(int x, int val, int cn) {
x += off;
p[x] = val;
cnt[x] = cn;
x /= 2;
while (x > 0) {
tour[x] = (tour[x * 2] + tour[x * 2 + 1]) % mod;
p[x] = (p[x * 2] + p[x * 2 + 1]) % mod;
cnt[x] = cnt[x * 2] + cnt[x * 2 + 1];
tour[x] += mul(p[x * 2 + 1], cnt[x * 2]);
tour[x] %= mod;
x /= 2;
}
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%d", a+i);
for (int i = 0; i < m; i++)
scanf("%d", b+i);
for (int i = 0; i < m; i++)
v.push_back(b[i]);
sort(v.begin(), v.end());
for (int i = 0; i < m; i++)
b[i] = lower_bound(v.begin(), v.end(), b[i]) - v.begin();
int has = 0;
pot[0] = 1;
for (int i = 1; i <= m; i++) pot[i] = mul(pot[i - 1], base);
for (int i = 0; i < n; i++) as[a[i]] = i;
for (int i = 1; i <= n; i++) {
has += mul(pot[n - i], as[i]);
has %= mod;
}
vector< int > sol;
for (int i = 0; i <= m - n; i++) {
if (i == 0) {
for (int j = 0; j < n; j++) {
update(b[j], pot[m - j - 1], 1);
}
}
//printf("debug: %d %d\n", mul(has, pot[m - n - i]), tour[1]);
if (mul(has, pot[m - n - i]) == tour[1])
sol.push_back(i + 1);
update(b[i], 0, 0);
update(b[i + n], pot[m - n - i - 1], 1);
}
printf("%d\n", sol.size());
for (int i = 0; i < sol.size(); i++) {
printf("%d ", sol[i]);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |