Submission #376113

#TimeUsernameProblemLanguageResultExecution timeMemory
376113YJULottery (CEOI18_lot)C++14
100 / 100
1413 ms12652 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector,Ofast") using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef long double ld; const ll N=1e4+5; const ll MOD=1e9+7; const ll INF=(1LL<<61); const ld pi=acos(-1); #define REP(i,n) for(int i=0;i<n;++i) #define REP1(i,n) for(int i=1;i<=n;++i) #define pb push_back #define mp make_pair #define X first #define Y second #define lwb lower_bound #define SZ(_a) (ll)_a.size() ll n,len,q,x; ll u[N],ans[N][105],e[N]; vector<ll> query; void solve(){ memset(ans,0,sizeof(ans)); for(int l=1;l+len<=n;l++){ //matching i with i+l ll cnt=0; for(int i=0;i<len;i++)if(u[i]==u[i+l])++cnt; for(int i=0;i+l+len<=n;i++){ //k>=len-cnt; ll id=lwb(query.begin(),query.end(),len-cnt)-query.begin(); ++ans[i][id]; ++ans[i+l][id]; cnt-=(u[i]==u[i+l]); cnt+=(u[i+len]==u[i+l+len]); } } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n>>len; REP(i,n)cin>>u[i]; cin>>q; REP(i,q){ cin>>e[i]; query.pb(e[i]); } sort(query.begin(),query.end()); query.erase(unique(query.begin(),query.end()),query.end()); solve(); REP(i,n)REP1(j,q)ans[i][j]+=ans[i][j-1]; REP(i,q){ ll id=lwb(query.begin(),query.end(),e[i])-query.begin(); REP(j,n-len+1)cout<<ans[j][id]<<" \n"[j==n-len]; } return 0; } /* 7 1 5 0 5 0 7 0 3 0 4 0 4 3 0 2 1 0 */
#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...