# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
347404 | kingfran1907 | Matching (CEOI11_mat) | C++14 | 1331 ms | 46092 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |