답안 #287299

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287299 2020-08-31T15:08:17 Z Blagojce Examination (JOI19_examination) C++11
100 / 100
1818 ms 165404 KB
#include <bits/stdc++.h> 
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
 
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;
 
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 2e5+5;
 
const ll A = 911382323;
const ll B = 972663749;

int n, m;
int s[mxn], t[mxn];
int a[mxn], b[mxn], c[mxn];
int ans[mxn];
int arr[mxn];

int range1;
int range2;

void compress(){
	vector<pii> v;
	vector<pii> g;
	fr(i, 0, n){
		v.pb({s[i], i+1});
		g.pb({t[i], i+1});
	}
	fr(i, 0, m){
		v.pb({a[i],-i-1});
		g.pb({b[i],-i-1});
	}
	sort(all(v));
	sort(all(g));
	int nwv = 0;
	for(auto u : v){
		nwv ++;
		if(u.nd > 0) s[u.nd-1] = nwv; 
		if(u.nd < 0) a[-u.nd-1] = nwv;
		
	}
	range1 = nwv;
	nwv = 0;
	for(auto u : g){
		nwv ++;
		if(u.nd > 0) t[u.nd-1] = nwv;
		if(u.nd < 0) b[-u.nd-1] = nwv;
	}
	range2 = nwv;
}

const int bsz = 1000;
int bit[500][mxn];
int cnt[mxn];
void update(int block, int k, int v){
	while(k < mxn){
		bit[block][k] += v;
		k += k&-k;
	}
}
int sum(int block, int k){
	int s = 0;
	while(k > 0){
		s += bit[block][k];
		k -= k&-k;
	}
	return s;
}

void solve(){
	cin >> n >> m;
	vector<int> v;
	fr(i, 0, n){
		cin >> s[i] >> t[i];
		v.pb(i);
	}
	sort(all(v), [](const int &i, const int &j){
		return s[i]+t[i] > s[j] + t[j];
	});
	int oldsum[n];
	fr(i, 0, n){
		oldsum[i] = s[v[i]] + t[v[i]];
	}
	
	
	vector<int> g;
	fr(i, 0, m){
		cin >> a[i] >> b[i] >> c[i];
		g.pb(i);
	}
	sort(all(g), [](const int &i, const int &j){
		return c[i] > c[j];
	});
	compress();
	
	
	int pos = 0;
	int totb = (range1+bsz-1)/bsz;
		
	for(auto u : g){
		while(pos < n && oldsum[pos] >= c[u]){
			arr[s[v[pos]]] = t[v[pos]];
			
			int bi = (s[v[pos]]-1)/bsz;
			update(bi, t[v[pos]], +1);
			++cnt[bi];
			++pos;
		}	
		int bi = (a[u]-1)/bsz;
		int p = a[u];
		while((p-1)/bsz == bi){
			if(arr[p] >= b[u]) ans[u] ++;
			++p;
		}
		fr(j, bi+1, totb+1){
			ans[u] += cnt[j]-sum(j, b[u]-1);
		}
	}
	fr(i, 0, m){
		cout<<ans[i]<<endl;
	}
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tc = 1;
	//cin >> tc;
	while(tc--) solve();
}/*
10 1
41304 98327
91921 28251
85635 59191
30361 72671
28949 96958
99041 37826
10245 2726
19387 20282
60366 87723
95388 49726
52302 69501 66009*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 17 ms 996 KB Output is correct
8 Correct 15 ms 996 KB Output is correct
9 Correct 16 ms 996 KB Output is correct
10 Correct 14 ms 996 KB Output is correct
11 Correct 15 ms 996 KB Output is correct
12 Correct 16 ms 996 KB Output is correct
13 Correct 16 ms 996 KB Output is correct
14 Correct 16 ms 996 KB Output is correct
15 Correct 16 ms 996 KB Output is correct
16 Correct 13 ms 868 KB Output is correct
17 Correct 13 ms 996 KB Output is correct
18 Correct 12 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1554 ms 160568 KB Output is correct
2 Correct 1557 ms 160676 KB Output is correct
3 Correct 1543 ms 160912 KB Output is correct
4 Correct 1074 ms 105584 KB Output is correct
5 Correct 1196 ms 91912 KB Output is correct
6 Correct 804 ms 26788 KB Output is correct
7 Correct 1818 ms 133272 KB Output is correct
8 Correct 1452 ms 135332 KB Output is correct
9 Correct 1530 ms 116644 KB Output is correct
10 Correct 1094 ms 86692 KB Output is correct
11 Correct 755 ms 90404 KB Output is correct
12 Correct 564 ms 9252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1554 ms 160568 KB Output is correct
2 Correct 1557 ms 160676 KB Output is correct
3 Correct 1543 ms 160912 KB Output is correct
4 Correct 1074 ms 105584 KB Output is correct
5 Correct 1196 ms 91912 KB Output is correct
6 Correct 804 ms 26788 KB Output is correct
7 Correct 1818 ms 133272 KB Output is correct
8 Correct 1452 ms 135332 KB Output is correct
9 Correct 1530 ms 116644 KB Output is correct
10 Correct 1094 ms 86692 KB Output is correct
11 Correct 755 ms 90404 KB Output is correct
12 Correct 564 ms 9252 KB Output is correct
13 Correct 1395 ms 163420 KB Output is correct
14 Correct 1589 ms 163620 KB Output is correct
15 Correct 1552 ms 163236 KB Output is correct
16 Correct 1113 ms 108452 KB Output is correct
17 Correct 1118 ms 92932 KB Output is correct
18 Correct 843 ms 28108 KB Output is correct
19 Correct 1401 ms 163528 KB Output is correct
20 Correct 1503 ms 163828 KB Output is correct
21 Correct 1321 ms 155468 KB Output is correct
22 Correct 1101 ms 86324 KB Output is correct
23 Correct 757 ms 90276 KB Output is correct
24 Correct 560 ms 9180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 17 ms 996 KB Output is correct
8 Correct 15 ms 996 KB Output is correct
9 Correct 16 ms 996 KB Output is correct
10 Correct 14 ms 996 KB Output is correct
11 Correct 15 ms 996 KB Output is correct
12 Correct 16 ms 996 KB Output is correct
13 Correct 16 ms 996 KB Output is correct
14 Correct 16 ms 996 KB Output is correct
15 Correct 16 ms 996 KB Output is correct
16 Correct 13 ms 868 KB Output is correct
17 Correct 13 ms 996 KB Output is correct
18 Correct 12 ms 868 KB Output is correct
19 Correct 1554 ms 160568 KB Output is correct
20 Correct 1557 ms 160676 KB Output is correct
21 Correct 1543 ms 160912 KB Output is correct
22 Correct 1074 ms 105584 KB Output is correct
23 Correct 1196 ms 91912 KB Output is correct
24 Correct 804 ms 26788 KB Output is correct
25 Correct 1818 ms 133272 KB Output is correct
26 Correct 1452 ms 135332 KB Output is correct
27 Correct 1530 ms 116644 KB Output is correct
28 Correct 1094 ms 86692 KB Output is correct
29 Correct 755 ms 90404 KB Output is correct
30 Correct 564 ms 9252 KB Output is correct
31 Correct 1395 ms 163420 KB Output is correct
32 Correct 1589 ms 163620 KB Output is correct
33 Correct 1552 ms 163236 KB Output is correct
34 Correct 1113 ms 108452 KB Output is correct
35 Correct 1118 ms 92932 KB Output is correct
36 Correct 843 ms 28108 KB Output is correct
37 Correct 1401 ms 163528 KB Output is correct
38 Correct 1503 ms 163828 KB Output is correct
39 Correct 1321 ms 155468 KB Output is correct
40 Correct 1101 ms 86324 KB Output is correct
41 Correct 757 ms 90276 KB Output is correct
42 Correct 560 ms 9180 KB Output is correct
43 Correct 1390 ms 165404 KB Output is correct
44 Correct 1386 ms 165328 KB Output is correct
45 Correct 1593 ms 165080 KB Output is correct
46 Correct 1126 ms 108960 KB Output is correct
47 Correct 1112 ms 94496 KB Output is correct
48 Correct 796 ms 27552 KB Output is correct
49 Correct 1725 ms 137780 KB Output is correct
50 Correct 1173 ms 137144 KB Output is correct
51 Correct 1307 ms 118960 KB Output is correct
52 Correct 1089 ms 88020 KB Output is correct
53 Correct 815 ms 91284 KB Output is correct