답안 #684716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684716 2023-01-22T11:25:09 Z vjudge1 Examination (JOI19_examination) C++17
100 / 100
451 ms 26500 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define endl "\n"
//~ #define int long long
 
typedef long long int ll;

const int MOD = 1e9 + 7;
const int maxN = 200000;

bool cmp(pair<int, int> a, pair<int, int> b){
	return a.first + a.second > b.first + b.second;
}

bool cmp2(tuple<int, int, int, int> a, tuple<int, int, int, int> b){
	return get<2>(a) > get<2>(b);
}

struct segTree {
    int size;
    vector<ll> sums;
    void init(int n){
        size = 1;
        while (size < n) size *= 2;
        sums.assign(2 * size, 0LL);
    }
    void set(int i, int v, int x, int lx, int rx){
        if (rx - lx == 1){
            sums[x] += v;
            return;
        }
        int m = (lx + rx) / 2;
        if (i < m){
            set(i, v, 2 * x + 1, lx, m);
        }else{
            set(i, v, 2 * x + 2, m, rx);
        }
        sums[x] = sums[2 * x + 1] + sums[2 * x + 2];
    }
    void set(int i, int v){
        set (i, v, 0, 0, size);
    }

    ll sum(int l, int r, int x, int lx, int rx){
        if (lx >= r || l >= rx){
            return 0;
        }
        if (lx >= l && rx <= r){
            return sums[x];
        }
        int m = (lx + rx) / 2;
        ll s1 = sum(l, r, 2 * x + 1, lx, m);
        ll s2 = sum(l, r, 2 * x + 2, m, rx);
        return s1 + s2;
    }

    ll sum (int l, int r){
        return sum(l, r, 0, 0, size);
    }
};


void solve(){
	int n, q; cin >> n >> q;
	vector<pair<int, int>> v(n);
	set<int> sa;
	set<int> sb;
	for(int i = 0; i < n; i++){
		int x, y; cin >> x >> y;
		v[i] = {x, y};
		sa.insert(x);
		sb.insert(y);
	}
	map<int, int> a;
	map<int, int> b;
	int curr = 1;
	for(auto x : sa){
		a[x] = curr;
		curr++;
	}
	segTree sta; sta.init(curr);
	int sza = curr;
	curr = 1;
	for(auto x : sb){
		b[x] = curr;
		curr++;
	}
	segTree stb; stb.init(curr);
	int szb = curr;
	sort(v.begin(), v.end(), cmp);
	vector<tuple<int, int, int, int>> queries(q);
	for(int i = 0; i < q; i++){
		int x, y, z; cin >> x >> y >> z;
		int nx = sza;
		auto it = a.lower_bound(x);
		if(it != a.end()) nx = (*it).second;
		int ny = szb;
		it = b.lower_bound(y);
		if(it != b.end()) ny = (*it).second;
		queries[i] = {nx, ny, max(z, x + y), i};
	}
	sort(queries.begin(), queries.end(), cmp2);
	vector<int> ans(q);
	curr = 0;
	for(int i = 0; i < q; i++){
		while(curr < n && v[curr].first + v[curr].second >= get<2>(queries[i])){
			sta.set(a[v[curr].first], 1);
			stb.set(b[v[curr].second], 1);
			curr++;
		}
		int total = curr - sta.sum(1, get<0>(queries[i])) - stb.sum(1, get<1>(queries[i]));
		ans[get<3>(queries[i])] = total;
	}
	for(int x : ans) cout << x << endl;
}
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    //freopen("inpt.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    //~ int tt; cin >> tt;
    int tt = 1;
    for(int t = 1; t <= tt; t++){
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 11 ms 1056 KB Output is correct
8 Correct 7 ms 1108 KB Output is correct
9 Correct 10 ms 980 KB Output is correct
10 Correct 5 ms 724 KB Output is correct
11 Correct 7 ms 724 KB Output is correct
12 Correct 4 ms 340 KB Output is correct
13 Correct 8 ms 1108 KB Output is correct
14 Correct 10 ms 1080 KB Output is correct
15 Correct 7 ms 1080 KB Output is correct
16 Correct 7 ms 744 KB Output is correct
17 Correct 6 ms 676 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 365 ms 17472 KB Output is correct
2 Correct 394 ms 17488 KB Output is correct
3 Correct 320 ms 17512 KB Output is correct
4 Correct 160 ms 10552 KB Output is correct
5 Correct 162 ms 10540 KB Output is correct
6 Correct 64 ms 3576 KB Output is correct
7 Correct 296 ms 17480 KB Output is correct
8 Correct 312 ms 17504 KB Output is correct
9 Correct 291 ms 17496 KB Output is correct
10 Correct 157 ms 10444 KB Output is correct
11 Correct 153 ms 10324 KB Output is correct
12 Correct 45 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 365 ms 17472 KB Output is correct
2 Correct 394 ms 17488 KB Output is correct
3 Correct 320 ms 17512 KB Output is correct
4 Correct 160 ms 10552 KB Output is correct
5 Correct 162 ms 10540 KB Output is correct
6 Correct 64 ms 3576 KB Output is correct
7 Correct 296 ms 17480 KB Output is correct
8 Correct 312 ms 17504 KB Output is correct
9 Correct 291 ms 17496 KB Output is correct
10 Correct 157 ms 10444 KB Output is correct
11 Correct 153 ms 10324 KB Output is correct
12 Correct 45 ms 3284 KB Output is correct
13 Correct 351 ms 17508 KB Output is correct
14 Correct 314 ms 17520 KB Output is correct
15 Correct 333 ms 17552 KB Output is correct
16 Correct 163 ms 10656 KB Output is correct
17 Correct 167 ms 10660 KB Output is correct
18 Correct 60 ms 3532 KB Output is correct
19 Correct 337 ms 17500 KB Output is correct
20 Correct 324 ms 17632 KB Output is correct
21 Correct 298 ms 17612 KB Output is correct
22 Correct 152 ms 10416 KB Output is correct
23 Correct 150 ms 10392 KB Output is correct
24 Correct 45 ms 3276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 11 ms 1056 KB Output is correct
8 Correct 7 ms 1108 KB Output is correct
9 Correct 10 ms 980 KB Output is correct
10 Correct 5 ms 724 KB Output is correct
11 Correct 7 ms 724 KB Output is correct
12 Correct 4 ms 340 KB Output is correct
13 Correct 8 ms 1108 KB Output is correct
14 Correct 10 ms 1080 KB Output is correct
15 Correct 7 ms 1080 KB Output is correct
16 Correct 7 ms 744 KB Output is correct
17 Correct 6 ms 676 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 365 ms 17472 KB Output is correct
20 Correct 394 ms 17488 KB Output is correct
21 Correct 320 ms 17512 KB Output is correct
22 Correct 160 ms 10552 KB Output is correct
23 Correct 162 ms 10540 KB Output is correct
24 Correct 64 ms 3576 KB Output is correct
25 Correct 296 ms 17480 KB Output is correct
26 Correct 312 ms 17504 KB Output is correct
27 Correct 291 ms 17496 KB Output is correct
28 Correct 157 ms 10444 KB Output is correct
29 Correct 153 ms 10324 KB Output is correct
30 Correct 45 ms 3284 KB Output is correct
31 Correct 351 ms 17508 KB Output is correct
32 Correct 314 ms 17520 KB Output is correct
33 Correct 333 ms 17552 KB Output is correct
34 Correct 163 ms 10656 KB Output is correct
35 Correct 167 ms 10660 KB Output is correct
36 Correct 60 ms 3532 KB Output is correct
37 Correct 337 ms 17500 KB Output is correct
38 Correct 324 ms 17632 KB Output is correct
39 Correct 298 ms 17612 KB Output is correct
40 Correct 152 ms 10416 KB Output is correct
41 Correct 150 ms 10392 KB Output is correct
42 Correct 45 ms 3276 KB Output is correct
43 Correct 445 ms 26396 KB Output is correct
44 Correct 450 ms 26488 KB Output is correct
45 Correct 451 ms 26444 KB Output is correct
46 Correct 213 ms 15040 KB Output is correct
47 Correct 205 ms 15004 KB Output is correct
48 Correct 64 ms 3328 KB Output is correct
49 Correct 432 ms 26460 KB Output is correct
50 Correct 431 ms 26444 KB Output is correct
51 Correct 371 ms 26500 KB Output is correct
52 Correct 190 ms 14828 KB Output is correct
53 Correct 174 ms 14892 KB Output is correct