답안 #1083193

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1083193 2024-09-02T17:48:28 Z StefanSebez Examination (JOI19_examination) C++14
0 / 100
1 ms 604 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=20;
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();
    //if(lb==0) return;
    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;
    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);
    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());
    int M=unique(Vals.begin(),Vals.end())-Vals.begin();
    Vals.resize(M);
    //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++){
		//printf("%i: ",i);for(auto j:vals[i]) printf("%i ",j);printf("\n");
        vals[i].pb(-1);
        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);
        //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++;
        }
        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:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for(int i=lb;i<T[qind].size();i+=i&-i) T[qind][i]+=qval;
      |                  ~^~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     int n,q;scanf("%i%i",&n,&q);
      |             ~~~~~^~~~~~~~~~~~~~
examination.cpp:43:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |     for(int i=1;i<=n;i++) scanf("%i%i",&a[i].fi,&a[i].se);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:63:24: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         int x,y,z;scanf("%i%i%i",&x,&y,&z);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Runtime error 1 ms 604 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Runtime error 1 ms 604 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -