답안 #674168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674168 2022-12-23T11:11:39 Z Cookie Examination (JOI19_examination) C++14
100 / 100
1355 ms 119276 KB
#include<bits/stdc++.h>

#include<fstream>
//#include "factories.h"

using namespace std;
ifstream fin("sus.in");
ofstream fout("sus.out");
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
const int x[4] = {1, -1, 0, 0};
const int y[4] = {0, 0, 1, -1};
#define int long long
const int mxn = 1e5, sq = 800;
int block[mxn + 1];
int n, q;
vt<ll>compx, compy;
struct BIT{
    int bit[3 * mxn + 1];
    void upd(int p, int v){
        while(p <= 3 * mxn){
            bit[p] += v; p += p & (-p);
        }
    }
    int get(int p){
        int ans = 0;
        while(p){
            ans += bit[p];
            p -= p & (-p);
        }
        return(ans);
    }
};
BIT bit[sq + 1];
struct ob{
    int x, y, id;
    bool operator <(const ob &b){
        return(x < b.x);
    }
};
vt<ob>v;
struct qq{
    ll x, y, z; int id;
    bool operator <(const qq &b){
        return(z > b.z);
    }
};
qq a[mxn + 1];
int ans[mxn + 1];
qq queries[mxn + 1];
bool used[mxn + 1];
void upd(int id, int v){
    bit[block[id]].upd(v, 1);
}
int solve(int l, int r, int y){
    if(l > r)return(0);
    int bl = block[l], br = block[r];
    int ans  =0;
    if(bl == br){
        //for(int i = 1; i <= n; i++)cout << used[i] << " ";
        //cout << "\n";
        for(int i = l; i <= r; i++)ans += (v[i - 1].y >= y && used[i]);
        //cout << ans << "\n";
        return(ans);
    }
    for(int i = l; i < sq * (bl + 1); i++){
        
        ans += (v[i - 1].y >= y && used[i]);
    }
    for(int i = br * sq; i <= r; i++)ans += (v[i - 1].y >= y && used[i]);
    for(int i = bl + 1; i < br; i++){
        ans += bit[i].get(3 * mxn) - bit[i].get(y - 1);
    }
    return(ans);
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> q;
    for(int i = 1; i <= n; i++)block[i] = i / sq;
    
    forr(i, 0, n){
        cin >> a[i].x >> a[i].y; a[i].z = a[i].x + a[i].y;
        compx.pb(a[i].x); compy.pb(a[i].y);
        v.pb({a[i].x, a[i].y, i});
    }
    sort(v.begin(), v.end());
    //for(auto [x, y, id]: v)cout << x << " " << y << " " << id << "\n";
    for(int i = 0; i < v.size(); i++){
        a[v[i].id].id = i + 1;
    }
    sort(a, a + n);
    forr(i, 0, q){
        cin >> queries[i].x >> queries[i].y >> queries[i].z; queries[i].id = i;
    }
    sort(queries, queries + q);
    sort(compx.begin(), compx.end());
    sort(compy.begin(), compy.end());
    int mx = 0;
    forr(i, 0, n){
        a[i].x = lower_bound(compx.begin(), compx.end(), a[i].x) - compx.begin() + 1;
        a[i].y = lower_bound(compy.begin(), compy.end(), a[i].y) - compy.begin() + 1;
        v[i].y = lower_bound(compy.begin(), compy.end(), v[i].y) - compy.begin() + 1;
        
    }
    forr(i, 0, q){
        queries[i].x = lower_bound(compx.begin(), compx.end(), queries[i].x) - compx.begin() + 1;
        queries[i].y = lower_bound(compy.begin(), compy.end(), queries[i].y) - compy.begin() + 1;
    }
    int l = 0;
    for(int i = 0; i < q; i++){

        while(l < n && a[l].z >= queries[i].z){
            upd(a[l].id, a[l].y); used[a[l].id] = true;
            l++;
        }
        
        //cout << l << " ";
        //assert(a[queries[i].x].x == )
        ans[queries[i].id] = solve(queries[i].x, n, queries[i].y);
    }
    forr(i, 0, q)cout << ans[i] << "\n";
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:95:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<ob>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for(int i = 0; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
examination.cpp:105:9: warning: unused variable 'mx' [-Wunused-variable]
  105 |     int mx = 0;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 11 ms 1136 KB Output is correct
8 Correct 11 ms 1188 KB Output is correct
9 Correct 12 ms 1136 KB Output is correct
10 Correct 10 ms 1108 KB Output is correct
11 Correct 11 ms 1124 KB Output is correct
12 Correct 11 ms 1116 KB Output is correct
13 Correct 11 ms 1132 KB Output is correct
14 Correct 11 ms 1208 KB Output is correct
15 Correct 11 ms 1196 KB Output is correct
16 Correct 8 ms 1140 KB Output is correct
17 Correct 5 ms 1108 KB Output is correct
18 Correct 3 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 783 ms 116804 KB Output is correct
2 Correct 831 ms 116864 KB Output is correct
3 Correct 852 ms 116960 KB Output is correct
4 Correct 524 ms 36088 KB Output is correct
5 Correct 845 ms 116044 KB Output is correct
6 Correct 479 ms 36588 KB Output is correct
7 Correct 1355 ms 116844 KB Output is correct
8 Correct 538 ms 116704 KB Output is correct
9 Correct 745 ms 116704 KB Output is correct
10 Correct 717 ms 115892 KB Output is correct
11 Correct 233 ms 20708 KB Output is correct
12 Correct 132 ms 19792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 783 ms 116804 KB Output is correct
2 Correct 831 ms 116864 KB Output is correct
3 Correct 852 ms 116960 KB Output is correct
4 Correct 524 ms 36088 KB Output is correct
5 Correct 845 ms 116044 KB Output is correct
6 Correct 479 ms 36588 KB Output is correct
7 Correct 1355 ms 116844 KB Output is correct
8 Correct 538 ms 116704 KB Output is correct
9 Correct 745 ms 116704 KB Output is correct
10 Correct 717 ms 115892 KB Output is correct
11 Correct 233 ms 20708 KB Output is correct
12 Correct 132 ms 19792 KB Output is correct
13 Correct 762 ms 117308 KB Output is correct
14 Correct 831 ms 117144 KB Output is correct
15 Correct 863 ms 116816 KB Output is correct
16 Correct 505 ms 37420 KB Output is correct
17 Correct 721 ms 116588 KB Output is correct
18 Correct 464 ms 38680 KB Output is correct
19 Correct 747 ms 117164 KB Output is correct
20 Correct 803 ms 117192 KB Output is correct
21 Correct 818 ms 117260 KB Output is correct
22 Correct 700 ms 115996 KB Output is correct
23 Correct 225 ms 20740 KB Output is correct
24 Correct 140 ms 19720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 11 ms 1136 KB Output is correct
8 Correct 11 ms 1188 KB Output is correct
9 Correct 12 ms 1136 KB Output is correct
10 Correct 10 ms 1108 KB Output is correct
11 Correct 11 ms 1124 KB Output is correct
12 Correct 11 ms 1116 KB Output is correct
13 Correct 11 ms 1132 KB Output is correct
14 Correct 11 ms 1208 KB Output is correct
15 Correct 11 ms 1196 KB Output is correct
16 Correct 8 ms 1140 KB Output is correct
17 Correct 5 ms 1108 KB Output is correct
18 Correct 3 ms 980 KB Output is correct
19 Correct 783 ms 116804 KB Output is correct
20 Correct 831 ms 116864 KB Output is correct
21 Correct 852 ms 116960 KB Output is correct
22 Correct 524 ms 36088 KB Output is correct
23 Correct 845 ms 116044 KB Output is correct
24 Correct 479 ms 36588 KB Output is correct
25 Correct 1355 ms 116844 KB Output is correct
26 Correct 538 ms 116704 KB Output is correct
27 Correct 745 ms 116704 KB Output is correct
28 Correct 717 ms 115892 KB Output is correct
29 Correct 233 ms 20708 KB Output is correct
30 Correct 132 ms 19792 KB Output is correct
31 Correct 762 ms 117308 KB Output is correct
32 Correct 831 ms 117144 KB Output is correct
33 Correct 863 ms 116816 KB Output is correct
34 Correct 505 ms 37420 KB Output is correct
35 Correct 721 ms 116588 KB Output is correct
36 Correct 464 ms 38680 KB Output is correct
37 Correct 747 ms 117164 KB Output is correct
38 Correct 803 ms 117192 KB Output is correct
39 Correct 818 ms 117260 KB Output is correct
40 Correct 700 ms 115996 KB Output is correct
41 Correct 225 ms 20740 KB Output is correct
42 Correct 140 ms 19720 KB Output is correct
43 Correct 767 ms 119220 KB Output is correct
44 Correct 746 ms 119148 KB Output is correct
45 Correct 878 ms 119276 KB Output is correct
46 Correct 516 ms 37116 KB Output is correct
47 Correct 734 ms 117596 KB Output is correct
48 Correct 460 ms 34832 KB Output is correct
49 Correct 1182 ms 119220 KB Output is correct
50 Correct 500 ms 119020 KB Output is correct
51 Correct 674 ms 119152 KB Output is correct
52 Correct 746 ms 117720 KB Output is correct
53 Correct 239 ms 21568 KB Output is correct