이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define fs first
#define se second
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define pb push_back
#define SZ(v) (ll)v.size()
#define ALL(v) v.begin(),v.end()
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now ().time_since_epoch().count());
ll Rand (ll l, ll r) { return uniform_int_distribution<ll> (l, r) (rd); }
const int N = 1e6 + 7;
const int Mod = 1e9 + 7;///lon
const int INF = 1e9 + 7;
const int BASE = 137;
const int szBL = 350;
int n, m;
int a[N], b[N], pw[N];
struct Segment_Tree {
int m;
pii st[N << 2];
void init (int n) {
m = n;
}
void update (int id, int l, int r, int pos, int val) {
if (l > pos || r < pos) return;
if (l == r) {
if (val == 0) st[id] = MP(0, 0);
else st[id] = MP(val, 1);
return;
}
int mid = l + r >> 1;
update (id << 1, l, mid, pos, val);
update (id << 1 | 1, mid + 1, r, pos, val);
st[id].fs = (1LL * st[id << 1].fs * pw[st[id << 1 | 1].se] % Mod + st[id << 1 | 1].fs) % Mod;
st[id].se = st[id << 1].se + st[id << 1 | 1].se;
}
void update (int pos, int val) {
update (1, 1, m, pos, val);
}
}ST;
void solution () {
cin >> n >> m;
rep (i, 1, n) cin >> a[i];
rep (i, 1, m) cin >> b[i];
auto compress = [&] () {
vector<int> vals;
rep (i, 1, m) vals.pb(b[i]);
sort(ALL(vals));
rep (i, 1, m) {
b[i] = lower_bound(ALL(vals), b[i]) - vals.begin() + 1;
}
};
compress();
int curHs = 0, sum = 0;
pw[0] = 1;
rep (i, 1, n) {
curHs = (1LL * curHs * BASE % Mod + a[i]) % Mod;
pw[i] = 1LL * pw[i - 1] * BASE % Mod;
sum = (sum + pw[i - 1]) % Mod;
}
ST.init(m);
vector<int> Ans;
rep (i, 1, n) {
ST.update (b[i], i);
}
if (ST.st[1].fs == curHs) Ans.pb(1);
rep (i, n + 1, m) {
curHs = (curHs + sum) % Mod;
// cout << curHs <<"\n";
ST.update (b[i - n], 0);
ST.update (b[i], i);
if (ST.st[1].fs == curHs) Ans.pb(i - n + 1);
}
cout << SZ(Ans) <<"\n";
iter (&id, Ans) cout << id <<" ";
}
#define file(name) freopen(name".inp","r",stdin); freopen(name".out","w",stdout);
main () {
// file("c");
ios_base :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
int num_Test = 1;
// cin >> num_Test;
while (num_Test--)
solution();
}
/*
no bug challenge +13
*/
컴파일 시 표준 에러 (stderr) 메시지
mat.cpp: In member function 'void Segment_Tree::update(int, int, int, int, int)':
mat.cpp:45:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
45 | int mid = l + r >> 1;
| ~~^~~
mat.cpp: At global scope:
mat.cpp:96:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
96 | main () {
| ^~~~
# | 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... |