답안 #1083163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083163 2024-09-02T17:05:54 Z StefanSebez Examination (JOI19_examination) C++14
0 / 100
3000 ms 21448 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
const int N=1e5+50;
struct Query{
    int x,y,z,i;
    bool operator <(Query a){return z<a.z;}
}Qs[N+50];
vector<int>T[N+50],vals[N+50];
pair<int,int>a[N+50];
int res[N+50];
void update(int qind,int qind1,int qval){
    int lb=lower_bound(vals[qind].begin(),vals[qind].end(),qind1)-vals[qind].begin();
    /*for(auto i:vals[qind]) printf("%i ",i);printf("\n");
    printf("+%i %i %i: %i\n",qind,qind1,qval,lb);*/
    for(int i=lb;i<T[qind].size();i+=i&-i) T[qind][i]+=qval;
}
void Update(int qind,int qind1,int qval,bool precalc){
    if(precalc) for(int i=qind;i<=N;i+=i&-i) vals[i].pb(qind1);
    else for(int i=qind;i<=N;i+=i&-i) update(i,qind1,qval);
}
int get(int qind,int qval){
    int sum=0;
    for(int i=T[qind].size()-1;i>=1;i-=i&-i) sum+=T[qind][i];
    int lb=lower_bound(vals[qind].begin(),vals[qind].end(),qval)-vals[qind].begin()-1;
    /*printf("|%i %i %i %i\n",qind,qval,lb,sum);
    for(auto i:vals[qind]) printf("%i ",i);printf("\n");
    for(auto i:T[qind]) printf("%i ",i);printf("\n");*/
    for(int i=lb;i>=1;i-=i&-i) sum-=T[qind][i];
    return sum;
}
int Get(int qind,int qval){
    int sum=0;
    for(int i=qind;i>=1;i-=i&-i){
        sum+=get(i,qval);
        //printf("%i %lld\n",i,sum);
    }
    return sum;
}
vector<int>Vals;
int Ind(int x){
    return upper_bound(Vals.begin(),Vals.end(),x)-Vals.begin()-1;
}
int main(){
    int n,q;scanf("%i%i",&n,&q);
    for(int i=1;i<=n;i++) scanf("%i%i",&a[i].fi,&a[i].se);
    Vals.pb(-1);
    for(int i=1;i<=n;i++) Vals.pb(a[i].fi);
    sort(Vals.begin(),Vals.end());
    Vals.resize(unique(Vals.begin(),Vals.end())-Vals.begin());
    //for(auto i:Vals) printf("%i ",i);printf("\n");
    for(int i=1;i<=n;i++) Update(Ind(a[i].fi),a[i].se,1,true);
    for(int i=0;i<=N;i++){
        vals[i].pb(0);
        sort(vals[i].begin(),vals[i].end());
        int m=unique(vals[i].begin(),vals[i].end())-vals[i].begin();
        vals[i].resize(m);
        for(int j=0;j<m;j++) T[i].pb(0);
        //if(i<=10){printf("%i: ",i);for(auto j:vals[i]) printf("%i ",j);printf("\n");}
    }
    for(int i=1;i<=n;i++) Update(Ind(a[i].fi),a[i].se,1,false);
    sort(a+1,a+n+1,[&](pair<int,int> i,pair<int,int> j){return i.fi+i.se<j.fi+j.se;});
    for(int i=1;i<=q;i++){
        int x,y,z;scanf("%i%i%i",&x,&y,&z);
        Qs[i]={x,y,z,i};
    }
    sort(Qs+1,Qs+q+1);
    //for(int i=1;i<=n;i++) printf("%i %i\n",a[i].fi,a[i].se);
    //for(int i=1;i<=q;i++) printf("%i %i %i\n",Qs[i].x,Qs[i].y,Qs[i].z);
    for(int i=1,j=1;j<=q;j++){
        while(i<=n && a[i].fi+a[i].se<Qs[j].z){
            Update(Ind(a[i].fi),a[i].se,-1,false);
            i++;
        }
        //if(j==1) printf("%i\n",Get(3,60));
        //printf("%i %i\n",i,j);
        res[Qs[j].i]=Get(N,Qs[j].y)-Get(Ind(Qs[j].x-1),Qs[j].y);
        //printf("*%i %i %i %i %i %i\n",Ind(Qs[j].x-1),Qs[j].x,Qs[j].y,Qs[j].z,Get(N,Qs[j].y),Get(Ind(Qs[j].x-1),Qs[j].y));
    }
    for(int i=1;i<=q;i++) printf("%i ",res[i]);
    return 0;
}

Compilation message

examination.cpp: In function 'void update(int, int, int)':
examination.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i=lb;i<T[qind].size();i+=i&-i) T[qind][i]+=qval;
      |                  ~^~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:49:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     int n,q;scanf("%i%i",&n,&q);
      |             ~~~~~^~~~~~~~~~~~~~
examination.cpp:50:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     for(int i=1;i<=n;i++) scanf("%i%i",&a[i].fi,&a[i].se);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:68:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         int x,y,z;scanf("%i%i%i",&x,&y,&z);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 11864 KB Output is correct
2 Correct 9 ms 11868 KB Output is correct
3 Correct 10 ms 11868 KB Output is correct
4 Correct 9 ms 11868 KB Output is correct
5 Correct 9 ms 11868 KB Output is correct
6 Correct 9 ms 11868 KB Output is correct
7 Correct 19 ms 12380 KB Output is correct
8 Correct 19 ms 12380 KB Output is correct
9 Correct 18 ms 12380 KB Output is correct
10 Execution timed out 3048 ms 12120 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3046 ms 21448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3046 ms 21448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 11864 KB Output is correct
2 Correct 9 ms 11868 KB Output is correct
3 Correct 10 ms 11868 KB Output is correct
4 Correct 9 ms 11868 KB Output is correct
5 Correct 9 ms 11868 KB Output is correct
6 Correct 9 ms 11868 KB Output is correct
7 Correct 19 ms 12380 KB Output is correct
8 Correct 19 ms 12380 KB Output is correct
9 Correct 18 ms 12380 KB Output is correct
10 Execution timed out 3048 ms 12120 KB Time limit exceeded
11 Halted 0 ms 0 KB -