Submission #384128

#TimeUsernameProblemLanguageResultExecution timeMemory
384128cpp219Lottery (CEOI18_lot)C++14
100 / 100
823 ms8428 KiB
#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)

lot.cpp:1: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    1 | #pragma GCC optimization "Ofast"
      | 
lot.cpp:2: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
lot.cpp: In function 'int main()':
lot.cpp:43:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   43 |     for (ll i = 1;i <= Q;i++) cin>>q[i],v.push_back(q[i]); compress();
      |     ^~~
lot.cpp:43:60: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   43 |     for (ll i = 1;i <= Q;i++) cin>>q[i],v.push_back(q[i]); compress();
      |                                                            ^~~~~~~~
lot.cpp:60:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   60 |         for (ll j = 1;j <= n - L + 1;j++) cout<<b[j][Find(q[i])]<<" "; cout<<"\n";
      |         ^~~
lot.cpp:60:72: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   60 |         for (ll j = 1;j <= n - L + 1;j++) cout<<b[j][Find(q[i])]<<" "; cout<<"\n";
      |                                                                        ^~~~
lot.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   37 |         freopen(task".inp","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...