Submission #522094

#TimeUsernameProblemLanguageResultExecution timeMemory
522094LoboLottery (CEOI18_lot)C++17
65 / 100
1556 ms32348 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]; 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) { vector<vector<int>> ps(n+10), qtd(n+10); for(int i = 0; i <= n+3; i++) { ps[i].resize(n+10,0); qtd[i].resize(n+10,0); } 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(); } map<long long, int> qtd; for(int i = 1; i <= n-l+1; i++) { qtd[subhash(i,i+l-1)]++; } int q; cin >> q >> q; for(int i = 1; i <= n-l+1; i++) { cout << qtd[subhash(i,i+l-1)]-1 << " "; }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(); }
#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...