Submission #522162

# Submission time Handle Problem Language Result Execution time Memory
522162 2022-02-04T02:33:03 Z phamhoanghiep Examination (JOI19_examination) C++14
0 / 100
397 ms 24964 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
struct qry{
    int x,y,z;
    int id;
    qry (int _x, int _y, int _z, int _id): x(_x), y(_y), z(_z), id(_id) {};
};
bool cmp(qry q1, qry q2) {
    return q1.x>q2.x;
}
vector<qry> vt;
int ans[maxn];
int S[maxn];
int T[maxn];
int X[maxn];
int Y[maxn];
int Z[maxn];
vector<int> val;
map<int,int> yay;
int n,q;
struct Binary_indexed_tree{
    int bit[1200021];
    int n;
    void init(int _n) {
        n=_n;
        for(int i=0 ; i<=n ; i++) bit[i]=0;
    }
    void upd(int pos, int val) {
        for(int i=pos ; i<=n ; i+=i&(-i)) bit[i]+=val;
    }
    int get_val(int pos) {
        int ans=0;
        for(int i=pos ; i>0 ; i-=i&(-i)) ans+=bit[i];
        return ans;
    }
}BIT;
void cdq(int l, int r) {
    if(l==r) return;
    int mid=(l+r)/2;
    cdq(l,mid); cdq(mid+1,r);
    int sum=0;
    int l_it=l;
    int r_it=mid+1;
    vector<int> record; // record the queries to reverse on BIT
    vector<qry> tmp; // for sorting according to y
    while(l_it<=mid&&r_it<=r) {
        if(vt[l_it].y>=vt[r_it].y) {
            if(!vt[l_it].id) {
                BIT.upd(vt[l_it].z,1);
                sum++;
                record.push_back(vt[l_it].z);
            }
            tmp.push_back(vt[l_it++]);
        }
        else {
            if(vt[r_it].id) {
                ans[vt[r_it].id]+=sum-BIT.get_val(vt[r_it].z-1);
            }
            tmp.push_back(vt[r_it++]);
        }
    }
    while(l_it<=mid) tmp.push_back(vt[l_it++]);
    while(r_it<=r) {
        if(vt[r_it].id) ans[vt[r_it].id]+=sum-BIT.get_val(vt[r_it].z-1);
        tmp.push_back(vt[r_it++]);
    }
    for(int i=l ; i<=r ; i++) vt[i]=tmp[i-l];
    for(int i: record) BIT.upd(i,-1);
    record.clear();
    tmp.clear();
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>q;
    for(int i=1 ; i<=n ; i++) {
        cin>>S[i]>>T[i];
        val.push_back(S[i]);
        val.push_back(T[i]);
        val.push_back(S[i]+T[i]);
    }
    for(int i=1 ; i<=q ; i++) {
        cin>>X[i]>>Y[i]>>Z[i];
        val.push_back(X[i]);
        val.push_back(Y[i]);
        val.push_back(Z[i]);
    }
    sort(val.begin(),val.end());
    int cr=0;
    for(int i=0 ; i<val.size() ; i++) {
        if(!i||val[i]!=val[i-1]) {
            cr++;
            yay[val[i]]=cr;
        }
    }
    BIT.init(cr+5);
    for(int i=1 ; i<=n ; i++) {
        vt.push_back(qry(yay[S[i]],yay[T[i]],yay[S[i]+T[i]],0));
    }
    for(int i=1 ; i<=q ; i++) {
        vt.push_back(qry(yay[X[i]],yay[Y[i]],yay[Z[i]],i));
    }
    sort(vt.begin(),vt.end(),&cmp);
    cdq(0,n+q-1);
    for(int i=1 ; i<=q ; i++) {
        cout<<ans[i]<<'\n';
    }
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:91:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for(int i=0 ; i<val.size() ; i++) {
      |                   ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 14 ms 1868 KB Output is correct
8 Correct 12 ms 1868 KB Output is correct
9 Correct 13 ms 1856 KB Output is correct
10 Correct 9 ms 1480 KB Output is correct
11 Incorrect 9 ms 1484 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 397 ms 24964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 397 ms 24964 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 14 ms 1868 KB Output is correct
8 Correct 12 ms 1868 KB Output is correct
9 Correct 13 ms 1856 KB Output is correct
10 Correct 9 ms 1480 KB Output is correct
11 Incorrect 9 ms 1484 KB Output isn't correct
12 Halted 0 ms 0 KB -