제출 #503907

#제출 시각아이디문제언어결과실행 시간메모리
503907krit3379Lottery (CEOI18_lot)C++17
45 / 100
3079 ms1032 KiB
#include<bits/stdc++.h>
using namespace std;
#define N 10005

int a[N],ans[105][N],que[105],p,sz;
map<int,int> in;
vector<short> pos[N];

int main(){
    int n,m,l,q,i,j,k,cnt,x;
    scanf("%d %d",&n,&l);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    m=n-l+1;
    scanf("%d",&q);
    for(i=1;i<=q;i++){
        scanf("%d",&que[i]);
    }
    for(i=1;i<=n;i++){
        if(!in.count(a[i]))in[a[i]]=++sz;
        pos[in[a[i]]].push_back(i);
    }
    for(i=1;i<=m;i++){
        vector<short> v(n+5,l);
        for(j=0;j<l;j++){
            p=in[a[i+j]];
            for(auto x:pos[p]){
                v[max(x-j,0)]--;
            }
        }
        //for(j=1;j<=m;j++)printf("%d ",v[j]);printf(" vv\n");
        sort(v.begin()+1,v.begin()+m+1);
        for(j=1;j<=q;j++){
            int x=upper_bound(v.begin()+1,v.begin()+m+1,que[j])-(v.begin());
            ans[j][i]=x-2;
        }
    }
    for(i=1;i<=q;i++){
        for(j=1;j<=m;j++)printf("%d ",ans[i][j]);
        printf("\n");
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

lot.cpp: In function 'int main()':
lot.cpp:10:21: warning: unused variable 'k' [-Wunused-variable]
   10 |     int n,m,l,q,i,j,k,cnt,x;
      |                     ^
lot.cpp:10:23: warning: unused variable 'cnt' [-Wunused-variable]
   10 |     int n,m,l,q,i,j,k,cnt,x;
      |                       ^~~
lot.cpp:10:27: warning: unused variable 'x' [-Wunused-variable]
   10 |     int n,m,l,q,i,j,k,cnt,x;
      |                           ^
lot.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d %d",&n,&l);
      |     ~~~~~^~~~~~~~~~~~~~~
lot.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     for(i=1;i<=n;i++)scanf("%d",&a[i]);
      |                      ~~~~~^~~~~~~~~~~~
lot.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d",&q);
      |     ~~~~~^~~~~~~~~
lot.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%d",&que[i]);
      |         ~~~~~^~~~~~~~~~~~~~
#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...