답안 #894391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
894391 2023-12-28T08:29:37 Z ttamx Examination (JOI19_examination) C++14
100 / 100
196 ms 14396 KB
#include<bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;

using ll = long long;
using db = long double;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<db>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<db,db>;
const int INF=0x3fffffff;
// const int MOD=1000000007;
const int MOD=998244353;
const ll LINF=0x1fffffffffffffff;
const db DINF=numeric_limits<db>::infinity();
const db EPS=1e-9;
const db PI=acos(db(-1));

const int N=2e5+5;

int n,q;
int ans[N];
vector<int> v;

struct point{
    int x,y,z,i;
    bool operator<(const point &o)const{
        if(x!=o.x)return x>o.x;
        if(y!=o.y)return y>o.y;
        return i<o.i;
    }
}a[N],b[N];

struct fenwick{
    int t[N];
    void update(int i,int v){
        for(;i<=n+q;i+=i&-i)t[i]+=v;
    }
    int query(int i){
        int res=0;
        for(;i>0;i-=i&-i)res+=t[i];
        return res;
    }
}f;

void CDQ(int l,int r){
    if(l==r)return;
    int m=(l+r)/2;
    CDQ(l,m);
    CDQ(m+1,r);
    for(int i=l,j=m+1,p=l;p<=r;){
        if(j>r||(i<=m&&a[i].y>=a[j].y)){
            b[p++]=a[i];
            if(a[i].i==0)f.update(a[i].z,1);
            i++;
        }else{
            b[p++]=a[j];
            if(a[j].i)ans[a[j].i]+=f.query(n+q)-f.query(a[j].z-1);
            j++;
        }
    }
    for(int i=l;i<=m;i++)if(a[i].i==0)f.update(a[i].z,-1);
    for(int i=l;i<=r;i++)a[i]=b[i];
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> q;
    for(int i=1;i<=n;i++){
        cin >> a[i].x >> a[i].y;
        a[i].z=a[i].x+a[i].y;
        v.emplace_back(a[i].z);
    }
    for(int i=n+1;i<=n+q;i++){
        cin >> a[i].x >> a[i].y >> a[i].z;
        v.emplace_back(a[i].z);
        a[i].i=i-n;
    }
    sort(all(v));
    for(int i=1;i<=n+q;i++)a[i].z=lower_bound(all(v),a[i].z)-v.begin()+1;
    sort(a+1,a+n+q+1);
    CDQ(1,n+q);
    for(int i=1;i<=q;i++)cout << ans[i] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4564 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 5 ms 4572 KB Output is correct
8 Correct 5 ms 4776 KB Output is correct
9 Correct 5 ms 4764 KB Output is correct
10 Correct 5 ms 4700 KB Output is correct
11 Correct 5 ms 4700 KB Output is correct
12 Correct 3 ms 4576 KB Output is correct
13 Correct 4 ms 4696 KB Output is correct
14 Correct 5 ms 4760 KB Output is correct
15 Correct 4 ms 4700 KB Output is correct
16 Correct 3 ms 4700 KB Output is correct
17 Correct 5 ms 4700 KB Output is correct
18 Correct 3 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 11508 KB Output is correct
2 Correct 149 ms 11520 KB Output is correct
3 Correct 148 ms 11472 KB Output is correct
4 Correct 133 ms 10764 KB Output is correct
5 Correct 131 ms 10900 KB Output is correct
6 Correct 78 ms 10160 KB Output is correct
7 Correct 132 ms 11468 KB Output is correct
8 Correct 130 ms 11412 KB Output is correct
9 Correct 127 ms 11456 KB Output is correct
10 Correct 118 ms 10752 KB Output is correct
11 Correct 117 ms 10628 KB Output is correct
12 Correct 89 ms 9864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 150 ms 11508 KB Output is correct
2 Correct 149 ms 11520 KB Output is correct
3 Correct 148 ms 11472 KB Output is correct
4 Correct 133 ms 10764 KB Output is correct
5 Correct 131 ms 10900 KB Output is correct
6 Correct 78 ms 10160 KB Output is correct
7 Correct 132 ms 11468 KB Output is correct
8 Correct 130 ms 11412 KB Output is correct
9 Correct 127 ms 11456 KB Output is correct
10 Correct 118 ms 10752 KB Output is correct
11 Correct 117 ms 10628 KB Output is correct
12 Correct 89 ms 9864 KB Output is correct
13 Correct 187 ms 12252 KB Output is correct
14 Correct 182 ms 12144 KB Output is correct
15 Correct 146 ms 11468 KB Output is correct
16 Correct 166 ms 11416 KB Output is correct
17 Correct 164 ms 11468 KB Output is correct
18 Correct 92 ms 10288 KB Output is correct
19 Correct 180 ms 12236 KB Output is correct
20 Correct 180 ms 12232 KB Output is correct
21 Correct 170 ms 12188 KB Output is correct
22 Correct 115 ms 10576 KB Output is correct
23 Correct 115 ms 10700 KB Output is correct
24 Correct 88 ms 9644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4564 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 5 ms 4572 KB Output is correct
8 Correct 5 ms 4776 KB Output is correct
9 Correct 5 ms 4764 KB Output is correct
10 Correct 5 ms 4700 KB Output is correct
11 Correct 5 ms 4700 KB Output is correct
12 Correct 3 ms 4576 KB Output is correct
13 Correct 4 ms 4696 KB Output is correct
14 Correct 5 ms 4760 KB Output is correct
15 Correct 4 ms 4700 KB Output is correct
16 Correct 3 ms 4700 KB Output is correct
17 Correct 5 ms 4700 KB Output is correct
18 Correct 3 ms 4700 KB Output is correct
19 Correct 150 ms 11508 KB Output is correct
20 Correct 149 ms 11520 KB Output is correct
21 Correct 148 ms 11472 KB Output is correct
22 Correct 133 ms 10764 KB Output is correct
23 Correct 131 ms 10900 KB Output is correct
24 Correct 78 ms 10160 KB Output is correct
25 Correct 132 ms 11468 KB Output is correct
26 Correct 130 ms 11412 KB Output is correct
27 Correct 127 ms 11456 KB Output is correct
28 Correct 118 ms 10752 KB Output is correct
29 Correct 117 ms 10628 KB Output is correct
30 Correct 89 ms 9864 KB Output is correct
31 Correct 187 ms 12252 KB Output is correct
32 Correct 182 ms 12144 KB Output is correct
33 Correct 146 ms 11468 KB Output is correct
34 Correct 166 ms 11416 KB Output is correct
35 Correct 164 ms 11468 KB Output is correct
36 Correct 92 ms 10288 KB Output is correct
37 Correct 180 ms 12236 KB Output is correct
38 Correct 180 ms 12232 KB Output is correct
39 Correct 170 ms 12188 KB Output is correct
40 Correct 115 ms 10576 KB Output is correct
41 Correct 115 ms 10700 KB Output is correct
42 Correct 88 ms 9644 KB Output is correct
43 Correct 196 ms 14232 KB Output is correct
44 Correct 195 ms 14092 KB Output is correct
45 Correct 185 ms 14028 KB Output is correct
46 Correct 170 ms 12456 KB Output is correct
47 Correct 173 ms 12800 KB Output is correct
48 Correct 101 ms 9928 KB Output is correct
49 Correct 171 ms 14004 KB Output is correct
50 Correct 175 ms 14396 KB Output is correct
51 Correct 168 ms 14028 KB Output is correct
52 Correct 155 ms 12496 KB Output is correct
53 Correct 122 ms 11536 KB Output is correct