제출 #522099

#제출 시각아이디문제언어결과실행 시간메모리
522099LoboLottery (CEOI18_lot)C++17
0 / 100
2 ms588 KiB
#include<bits/stdc++.h> using namespace std; const long long inf = (long long) 1e18 + 10; const int inf1 = (int) 1e9 + 10; // #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define maxn 10200 int n, l, a[maxn], ps[2020][2020], qtd[2020][2020]; vector<int> pos[maxn]; long long pw[maxn], hsh[maxn]; long long mod = 1e9 + 7; void prephash() { pw[0] = 1; pw[1] = 5131; for(int i = 2; i <= n; i++) { pw[i] = pw[i-1]*pw[1]; pw[i]%= mod; } for(int i = 1; i <= n; i++) { hsh[i] = hsh[i-1]*pw[1] + a[i]; hsh[i]%= mod; } } long long subhash(int l, int r) { return ((hsh[r] - hsh[l-1]*pw[r-l+1])%mod + mod)%mod; } void solve() { cin >> n >> l; vector<int> cc; for(int i = 1; i <= n; i++) { cin >> a[i]; cc.pb(a[i]); } sort(all(cc)); cc.erase(unique(all(cc)),cc.end()); if(n <= 2000) { for(int i = 1; i <= n; i++) { a[i] = upper_bound(all(cc),a[i]) - cc.begin(); pos[a[i]].pb(i-l+1); } for(int i = 1; i <= n; i++) { for(auto x : pos[i]) { for(auto y : pos[i]) { if(x == y) continue; // cout << " " << x << " " << y << endl; int x1 = x; int y1 = y; int x2 = x+l; int y2 = y+l; if(x1 <= 0) { y1+= 1-x1; x1 = 1; } if(y1 <= 0) { x1+= 1-y1; y1 = 1; } ps[x1][y1]++; if(x2 <= n && y2 <= n) ps[x2][y2]--; // cout << x1 << " " << y1 << " " << x2 << " " << y2 << endl; } } } for(int i = 1; i <= n; i++) { //coordenada que comeca em (1,i); int x = 2; int y = i+1; while(y <= n) { ps[x][y]+= ps[x-1][y-1]; x++; y++; } } for(int i = 2; i <= n; i++) { //coordenada que comeca em (i,1); int x = i+1; int y = 2; while(x <= n) { ps[x][y]+= ps[x-1][y-1]; x++; y++; } } // for(int i = 1; i <= n; i++) { // for(int j = 1; j <= n; j++) { // cout << i << " " << j << " " << ps[i][j] << " " << endl; // } // } for(int i = 1; i <= n-l+1; i++) { for(int j = 1; j <= n-l+1; j++) { if(i == j) continue; qtd[i][l-ps[i][j]]++; } for(int j = 1; j <= l; j++) { qtd[i][j]+= qtd[i][j-1]; } } int q; cin >> q; while(q--) { int val; cin >> val; for(int i = 1; i <= n-l+1; i++) { cout << qtd[i][val] << " "; }cout << endl; } } else { for(int i = 1; i <= n; i++) { a[i] = upper_bound(all(cc),a[i]) - cc.begin(); prephash(); } vector<pair<long long,int>> v; vector<int> ans(n+5,0); for(int i = 1; i <= n-l+1; i++) { v.pb(mp(subhash(i,i+l-1),i)); } sort(all(v)); int id = 0; for(int i = 1; i < v.size(); i++) { if(v[i].fr == v[i-1].fr) continue; else { int sz = i-id; while(id != i) { ans[v[id].sc] = sz-1; id++; } } } int sz = ((int) v.size())-id; while(id != ((int) v.size())) { ans[v[id].sc] = sz-1; id++; } int q; cin >> q >> q; for(int i = 1; i <= n-l+1; i++) { cout << ans[i] << " "; }cout << endl; } } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); freopen("in.in", "r", stdin); //freopen("out.out", "w", stdout); int tt = 1; // cin >> tt; while(tt--) solve(); }

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

lot.cpp: In function 'void solve()':
lot.cpp:155:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  155 |         for(int i = 1; i < v.size(); i++) {
      |                        ~~^~~~~~~~~~
lot.cpp: In function 'int32_t main()':
lot.cpp:183:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  183 |     freopen("in.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#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...