답안 #684715

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684715 2023-01-22T11:24:42 Z esomer Examination (JOI19_examination) C++17
100 / 100
435 ms 31372 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 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 7 ms 1236 KB Output is correct
8 Correct 7 ms 1272 KB Output is correct
9 Correct 8 ms 1236 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 5 ms 852 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 8 ms 1200 KB Output is correct
14 Correct 7 ms 1224 KB Output is correct
15 Correct 7 ms 1236 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 5 ms 852 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 321 ms 20060 KB Output is correct
2 Correct 333 ms 20040 KB Output is correct
3 Correct 316 ms 20008 KB Output is correct
4 Correct 160 ms 12296 KB Output is correct
5 Correct 161 ms 12468 KB Output is correct
6 Correct 66 ms 4568 KB Output is correct
7 Correct 299 ms 19880 KB Output is correct
8 Correct 300 ms 19896 KB Output is correct
9 Correct 275 ms 19860 KB Output is correct
10 Correct 149 ms 12044 KB Output is correct
11 Correct 150 ms 12196 KB Output is correct
12 Correct 46 ms 4176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 321 ms 20060 KB Output is correct
2 Correct 333 ms 20040 KB Output is correct
3 Correct 316 ms 20008 KB Output is correct
4 Correct 160 ms 12296 KB Output is correct
5 Correct 161 ms 12468 KB Output is correct
6 Correct 66 ms 4568 KB Output is correct
7 Correct 299 ms 19880 KB Output is correct
8 Correct 300 ms 19896 KB Output is correct
9 Correct 275 ms 19860 KB Output is correct
10 Correct 149 ms 12044 KB Output is correct
11 Correct 150 ms 12196 KB Output is correct
12 Correct 46 ms 4176 KB Output is correct
13 Correct 319 ms 20436 KB Output is correct
14 Correct 321 ms 20428 KB Output is correct
15 Correct 310 ms 20048 KB Output is correct
16 Correct 164 ms 12700 KB Output is correct
17 Correct 159 ms 12660 KB Output is correct
18 Correct 61 ms 4544 KB Output is correct
19 Correct 327 ms 20348 KB Output is correct
20 Correct 316 ms 20520 KB Output is correct
21 Correct 344 ms 20388 KB Output is correct
22 Correct 148 ms 12096 KB Output is correct
23 Correct 149 ms 12108 KB Output is correct
24 Correct 45 ms 4168 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 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 7 ms 1236 KB Output is correct
8 Correct 7 ms 1272 KB Output is correct
9 Correct 8 ms 1236 KB Output is correct
10 Correct 5 ms 852 KB Output is correct
11 Correct 5 ms 852 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 8 ms 1200 KB Output is correct
14 Correct 7 ms 1224 KB Output is correct
15 Correct 7 ms 1236 KB Output is correct
16 Correct 4 ms 724 KB Output is correct
17 Correct 5 ms 852 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 321 ms 20060 KB Output is correct
20 Correct 333 ms 20040 KB Output is correct
21 Correct 316 ms 20008 KB Output is correct
22 Correct 160 ms 12296 KB Output is correct
23 Correct 161 ms 12468 KB Output is correct
24 Correct 66 ms 4568 KB Output is correct
25 Correct 299 ms 19880 KB Output is correct
26 Correct 300 ms 19896 KB Output is correct
27 Correct 275 ms 19860 KB Output is correct
28 Correct 149 ms 12044 KB Output is correct
29 Correct 150 ms 12196 KB Output is correct
30 Correct 46 ms 4176 KB Output is correct
31 Correct 319 ms 20436 KB Output is correct
32 Correct 321 ms 20428 KB Output is correct
33 Correct 310 ms 20048 KB Output is correct
34 Correct 164 ms 12700 KB Output is correct
35 Correct 159 ms 12660 KB Output is correct
36 Correct 61 ms 4544 KB Output is correct
37 Correct 327 ms 20348 KB Output is correct
38 Correct 316 ms 20520 KB Output is correct
39 Correct 344 ms 20388 KB Output is correct
40 Correct 148 ms 12096 KB Output is correct
41 Correct 149 ms 12108 KB Output is correct
42 Correct 45 ms 4168 KB Output is correct
43 Correct 435 ms 31372 KB Output is correct
44 Correct 435 ms 31352 KB Output is correct
45 Correct 403 ms 31308 KB Output is correct
46 Correct 194 ms 18264 KB Output is correct
47 Correct 199 ms 18388 KB Output is correct
48 Correct 62 ms 4412 KB Output is correct
49 Correct 391 ms 31196 KB Output is correct
50 Correct 396 ms 31364 KB Output is correct
51 Correct 380 ms 31180 KB Output is correct
52 Correct 193 ms 18064 KB Output is correct
53 Correct 175 ms 17360 KB Output is correct