# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384128 | cpp219 | Lottery (CEOI18_lot) | C++14 | 823 ms | 8428 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimization "Ofast"
#pragma GCC optimization "unroll-loop"
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e4 + 9;
const ll inf = 1e9 + 7;
ll n,L,a[N],Q,q[N],b[N][103],ans[N][103],kq[N];
vector<ll> v;
ll Find(ll x){
if (kq[x]) return kq[x];
return kq[x] = lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}
void compress(){
sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
}
ll Dis(ll x,ll y){
ll cnt = 0;
for (ll i = x;i <= x + L - 1;i++) if (a[i] != a[i + y - x]) cnt++;
return cnt;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
}
cin>>n>>L;
for (ll i = 1;i <= n;i++) cin>>a[i];
cin>>Q;
for (ll i = 1;i <= Q;i++) cin>>q[i],v.push_back(q[i]); compress();
for (ll i = 2;i <= n - L + 1;i++){
ll now = Dis(1,i); //cout<<Find(now); return 0;
ll nxt = Find(now); b[1][nxt]++; b[i][nxt]++; //cout<<1<<" "<<i<<" "<<nxt<<":\n";
for (ll j = L + 1;j + i - 1 <= n;j++){
if (a[j - L] != a[j - L + i - 1]) now--;
if (a[j] != a[j + i - 1]) now++;
//cout<<j - L + 1<<" "<<j - L + i<<" "<<Find(now)<<"\n";
nxt = Find(now); b[j - L + 1][nxt]++; b[j - L + i][nxt]++;
}
//cout<<"\n";
}
//return 0;
//cout<<b[3][1]; return 0;
for (ll i = 1;i <= n;i++)
for (ll j = 1;j <= Q;j++) b[i][j] += b[i][j - 1];
for (ll i = 1;i <= Q;i++){
for (ll j = 1;j <= n - L + 1;j++) cout<<b[j][Find(q[i])]<<" "; cout<<"\n";
}
}
Compilation message (stderr)
# | 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... |