답안 #384128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
384128 2021-03-31T14:14:33 Z cpp219 Lottery (CEOI18_lot) C++14
100 / 100
823 ms 8428 KB
#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

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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 13 ms 1260 KB Output is correct
14 Correct 9 ms 1260 KB Output is correct
15 Correct 8 ms 1260 KB Output is correct
16 Correct 12 ms 1260 KB Output is correct
17 Correct 11 ms 1260 KB Output is correct
18 Correct 11 ms 1260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 485 ms 4460 KB Output is correct
2 Correct 690 ms 4588 KB Output is correct
3 Correct 308 ms 4588 KB Output is correct
4 Correct 282 ms 4624 KB Output is correct
5 Correct 87 ms 4588 KB Output is correct
6 Correct 230 ms 4588 KB Output is correct
7 Correct 87 ms 4588 KB Output is correct
8 Correct 146 ms 4588 KB Output is correct
9 Correct 248 ms 4588 KB Output is correct
10 Correct 255 ms 4720 KB Output is correct
11 Correct 17 ms 1644 KB Output is correct
12 Correct 150 ms 4204 KB Output is correct
13 Correct 110 ms 4588 KB Output is correct
14 Correct 124 ms 4608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 485 ms 4460 KB Output is correct
2 Correct 690 ms 4588 KB Output is correct
3 Correct 308 ms 4588 KB Output is correct
4 Correct 282 ms 4624 KB Output is correct
5 Correct 87 ms 4588 KB Output is correct
6 Correct 230 ms 4588 KB Output is correct
7 Correct 87 ms 4588 KB Output is correct
8 Correct 146 ms 4588 KB Output is correct
9 Correct 248 ms 4588 KB Output is correct
10 Correct 255 ms 4720 KB Output is correct
11 Correct 17 ms 1644 KB Output is correct
12 Correct 150 ms 4204 KB Output is correct
13 Correct 110 ms 4588 KB Output is correct
14 Correct 124 ms 4608 KB Output is correct
15 Correct 337 ms 4496 KB Output is correct
16 Correct 225 ms 4588 KB Output is correct
17 Correct 296 ms 4572 KB Output is correct
18 Correct 258 ms 4588 KB Output is correct
19 Correct 260 ms 4588 KB Output is correct
20 Correct 279 ms 4536 KB Output is correct
21 Correct 276 ms 4536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 13 ms 1260 KB Output is correct
14 Correct 9 ms 1260 KB Output is correct
15 Correct 8 ms 1260 KB Output is correct
16 Correct 12 ms 1260 KB Output is correct
17 Correct 11 ms 1260 KB Output is correct
18 Correct 11 ms 1260 KB Output is correct
19 Correct 485 ms 4460 KB Output is correct
20 Correct 690 ms 4588 KB Output is correct
21 Correct 308 ms 4588 KB Output is correct
22 Correct 282 ms 4624 KB Output is correct
23 Correct 87 ms 4588 KB Output is correct
24 Correct 230 ms 4588 KB Output is correct
25 Correct 87 ms 4588 KB Output is correct
26 Correct 146 ms 4588 KB Output is correct
27 Correct 248 ms 4588 KB Output is correct
28 Correct 255 ms 4720 KB Output is correct
29 Correct 17 ms 1644 KB Output is correct
30 Correct 150 ms 4204 KB Output is correct
31 Correct 110 ms 4588 KB Output is correct
32 Correct 124 ms 4608 KB Output is correct
33 Correct 337 ms 4496 KB Output is correct
34 Correct 225 ms 4588 KB Output is correct
35 Correct 296 ms 4572 KB Output is correct
36 Correct 258 ms 4588 KB Output is correct
37 Correct 260 ms 4588 KB Output is correct
38 Correct 279 ms 4536 KB Output is correct
39 Correct 276 ms 4536 KB Output is correct
40 Correct 739 ms 5224 KB Output is correct
41 Correct 16 ms 4608 KB Output is correct
42 Correct 283 ms 5228 KB Output is correct
43 Correct 258 ms 4972 KB Output is correct
44 Correct 262 ms 5100 KB Output is correct
45 Correct 823 ms 8300 KB Output is correct
46 Correct 23 ms 4844 KB Output is correct
47 Correct 353 ms 8428 KB Output is correct
48 Correct 351 ms 6704 KB Output is correct
49 Correct 327 ms 7292 KB Output is correct