이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FOD(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;
const int MAXN = 1e6 + 5;
const int MOD = 1e9 + 7;
inline void add(int &x, int val) {
x += val;
if (x >= MOD) x -= MOD;
if (x < 0) x += MOD;
}
int N, M, ori, a[MAXN], h[MAXN], it[4 * MAXN], Pow[MAXN], Pow1[MAXN], lazy[4 * MAXN], sl[4 * MAXN];
vector <int> nen;
void down(int id) {
FOR(i, id * 2, id * 2 + 1) {
lazy[i] += lazy[id];
add(it[i], 1ll * Pow1[sl[i]] * lazy[id] % MOD);
} lazy[id] = 0;
}
void update(int id, int l, int r, int x, int val) {
if (l == r) {
if (val > 0) it[id] = val, sl[id]++;
else it[id] = 0, sl[id]--;
return;
}
down(id);
int mid = l + r >> 1;
if (mid >= x) update(id * 2, l, mid, x, val);
else update(id * 2 + 1, mid + 1, r, x, val);
it[id] = 1ll * Pow[sl[id * 2 + 1]] * it[id * 2] % MOD;
add(it[id], it[id * 2 + 1]);
sl[id] = sl[id * 2] + sl[id * 2 + 1];
}
signed main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
file("TASK");
cin >> N >> M;
Pow[0] = 1;
Pow1[0] = 0;
FOR(i, 1, N) {
cin >> a[i];
ori = (1ll * M * ori + a[i]) % MOD;
Pow[i] = 1ll * Pow[i - 1] * M % MOD;
Pow1[i] = (1ll * Pow1[i - 1] * M + 1) % MOD;
}
FOR(i, 1, M) cin >> h[i], nen.emplace_back(h[i]);
sort(ALL(nen));
FOR(i, 1, M) h[i] = lower_bound(ALL(nen), h[i]) - nen.begin() + 1;
FOR(i, 1, N) update(1, 1, M, h[i], i);
vector <int> ans;
if (it[1] == ori) ans.emplace_back(1);
FOR(i, N + 1, M) {
update(1, 1, M, h[i - N], -1);
add(it[1], -Pow1[sl[1]]);
lazy[1]--;
update(1, 1, M, h[i], N);
if (it[1] == ori) ans.emplace_back(i - N + 1);
}
cout << ans.size() << '\n';
for (int x : ans) cout << x << ' ';
cerr << "Time elapsed: " << TIME << " s.\n";
return (0 ^ 0);
}
컴파일 시 표준 에러 (stderr) 메시지
mat.cpp: In function 'void update(int, int, int, int, int)':
mat.cpp:39:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int mid = l + r >> 1;
| ~~^~~
mat.cpp: In function 'int main()':
mat.cpp:9:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mat.cpp:49:5: note: in expansion of macro 'file'
49 | file("TASK");
| ^~~~
mat.cpp:9:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
mat.cpp:49:5: note: in expansion of macro 'file'
49 | file("TASK");
| ^~~~
# | 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... |