제출 #205957

#제출 시각아이디문제언어결과실행 시간메모리
205957parsa_mobedMatching (CEOI11_mat)C++14
92 / 100
2049 ms47316 KiB
#include <bits/stdc++.h> using namespace std; #define mid ((L+R)>>1) const int N = 1e6 + 5; int Base = 1e6 + 3; int a[N], b[N], p[N], pw[N], seg[N<<2], lazy[N<<2], fen[N], Hash, n, m; vector <int> ans, vec; void apply(int id, int val) { seg[id] = seg[id] * pw[val], lazy[id] += val; } void shift(int id) { if (lazy[id] == 0) return ; apply(id<<1, lazy[id]), apply(id<<1|1, lazy[id]); lazy[id] = 0; } void Set(int l, int val, int L = 0, int R = m, int id = 1) { if (R - L == 1) {seg[id] = val; return ;} shift(id); if (l < mid) Set(l, val, L, mid, id<<1); else Set(l, val, mid, R, id<<1|1); seg[id] = seg[id<<1] + seg[id<<1|1]; } int Get(int l, int r, int L = 0, int R = m, int id = 1) { if (r <= L || R <= l) return 0; if (l <= L && R <= r) return seg[id]; shift(id); return Get(l, r, L, mid, id<<1) + Get(l, r, mid, R, id<<1|1); } void add(int idx) { for (idx++; idx < N; idx += idx&(-idx)) fen[idx]++; } void rem(int idx) { for (idx++; idx < N; idx += idx&(-idx)) fen[idx]--; } int get(int idx) { int res = 0; for (idx++; idx; idx -= idx&(-idx)) res += fen[idx]; return res; } int main() { pw[0] = 1; for (int i = 1; i < N; i++) pw[i] = pw[i - 1] * Base; // -------------------------------------------------------------- scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) {int x; scanf("%d", &x); a[x - 1] = i;} for (int i = 0; i < m; i++) scanf("%d", b + i), vec.push_back(b[i]); sort(vec.begin(), vec.end()); for (int i = 0; i < m; i++) b[i] = lower_bound(vec.begin(), vec.end(), b[i]) - vec.begin(), p[b[i]] = i; for (int i = 0; i < n; i++) Hash = Hash * Base + a[i]; // -------------------------------------------------------------- int CurHash = 0; for (int i = 0; i < m; i++) { if (i >= n) { CurHash -= get(b[i - n] - 1) * pw[n - 1] + Get(b[i - n] + 1, m); rem(b[i - n]), Set(b[i - n], 0); } apply(1, 1); CurHash = CurHash * Base + get(b[i]) + Get(b[i], m); add(b[i]), Set(b[i], 1); if (i >= n - 1) if (CurHash == Hash) ans.push_back(i - n + 2); } printf("%d\n", (int)ans.size()); for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]); printf("\n"); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

mat.cpp: In function 'int main()':
mat.cpp:68:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < ans.size(); i++) printf("%d ", ans[i]);
                     ~~^~~~~~~~~~~~
mat.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
mat.cpp:50:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 0; i < n; i++) {int x; scanf("%d", &x); a[x - 1] = i;}
                                         ~~~~~^~~~~~~~~~
mat.cpp:51:51: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (int i = 0; i < m; i++) scanf("%d", b + i), vec.push_back(b[i]);
                                 ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...