답안 #131752

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
131752 2019-07-17T14:30:32 Z MrTEK Examination (JOI19_examination) C++14
100 / 100
1874 ms 97276 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

using namespace __gnu_pbds;
using ordered_set = tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>;

const int N = 2e5 + 5;
const int inf = 1e9;

vector <int> v;
vector <pair<ii,ii>> queries;
map <int,int> id;
int answer,n,q,s[N],t[N],x[N],y[N],z[N],ans[N],tim;
ordered_set seg[N];

int query(int x,int val) {
	int answer = 0;
	for ( ; x <= N ; x += (x & -x))
		answer += seg[x].order_of_key({-val,inf});
	return answer;
}

void update(int x,int val) {
	for ( ; x > 0 ; x -= (x & -x))
		seg[x].insert({-val,++tim});
}

int main() {
	// freopen("04-01.txt","r",stdin);
	// freopen("04-01o2.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n >> q;
	for (int i = 1 ; i <= n ; i++) {
		cin >> s[i] >> t[i];
		v.push_back(t[i]);
		queries.push_back({{s[i],inf},{t[i],s[i] + t[i]}});
	}
	for (int i = 1 ; i <= q ; i++) {
		cin >> x[i] >> y[i] >> z[i];
		v.push_back(y[i]);
		queries.push_back({{x[i],i},{y[i],z[i]}});
	}
	sort(v.begin(),v.end());
	v.resize(unique(v.begin(),v.end()) - v.begin());
	int dsa = 0;
	for (auto i : v)
		id[i] = ++dsa;
	sort(queries.begin(),queries.end());
	reverse(queries.begin(),queries.end());
	for (auto i : queries) {
		if (i.first.second == inf)
			update(id[i.second.first],i.second.second);
		else
			ans[i.first.second] = query(id[i.second.first],i.second.second);
	}
	for (int i = 1 ; i <= q ; i++)
		cout << ans[i] << "\n";
}

# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 19192 KB Output is correct
2 Correct 26 ms 19192 KB Output is correct
3 Correct 26 ms 19320 KB Output is correct
4 Correct 26 ms 19320 KB Output is correct
5 Correct 26 ms 19192 KB Output is correct
6 Correct 25 ms 19192 KB Output is correct
7 Correct 39 ms 20848 KB Output is correct
8 Correct 39 ms 20856 KB Output is correct
9 Correct 39 ms 20856 KB Output is correct
10 Correct 31 ms 19704 KB Output is correct
11 Correct 37 ms 20856 KB Output is correct
12 Correct 31 ms 19704 KB Output is correct
13 Correct 38 ms 20860 KB Output is correct
14 Correct 38 ms 20856 KB Output is correct
15 Correct 39 ms 20728 KB Output is correct
16 Correct 35 ms 20728 KB Output is correct
17 Correct 31 ms 19576 KB Output is correct
18 Correct 32 ms 19580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1415 ms 80268 KB Output is correct
2 Correct 1466 ms 80480 KB Output is correct
3 Correct 1431 ms 80368 KB Output is correct
4 Correct 258 ms 37596 KB Output is correct
5 Correct 841 ms 80220 KB Output is correct
6 Correct 236 ms 37372 KB Output is correct
7 Correct 1560 ms 80296 KB Output is correct
8 Correct 1436 ms 79848 KB Output is correct
9 Correct 1336 ms 79580 KB Output is correct
10 Correct 751 ms 79964 KB Output is correct
11 Correct 249 ms 32104 KB Output is correct
12 Correct 223 ms 32016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1415 ms 80268 KB Output is correct
2 Correct 1466 ms 80480 KB Output is correct
3 Correct 1431 ms 80368 KB Output is correct
4 Correct 258 ms 37596 KB Output is correct
5 Correct 841 ms 80220 KB Output is correct
6 Correct 236 ms 37372 KB Output is correct
7 Correct 1560 ms 80296 KB Output is correct
8 Correct 1436 ms 79848 KB Output is correct
9 Correct 1336 ms 79580 KB Output is correct
10 Correct 751 ms 79964 KB Output is correct
11 Correct 249 ms 32104 KB Output is correct
12 Correct 223 ms 32016 KB Output is correct
13 Correct 1534 ms 80276 KB Output is correct
14 Correct 1646 ms 80220 KB Output is correct
15 Correct 1578 ms 80468 KB Output is correct
16 Correct 301 ms 37488 KB Output is correct
17 Correct 801 ms 80348 KB Output is correct
18 Correct 237 ms 37600 KB Output is correct
19 Correct 1558 ms 80164 KB Output is correct
20 Correct 1505 ms 80336 KB Output is correct
21 Correct 1641 ms 80220 KB Output is correct
22 Correct 742 ms 80024 KB Output is correct
23 Correct 246 ms 32092 KB Output is correct
24 Correct 202 ms 31964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 19192 KB Output is correct
2 Correct 26 ms 19192 KB Output is correct
3 Correct 26 ms 19320 KB Output is correct
4 Correct 26 ms 19320 KB Output is correct
5 Correct 26 ms 19192 KB Output is correct
6 Correct 25 ms 19192 KB Output is correct
7 Correct 39 ms 20848 KB Output is correct
8 Correct 39 ms 20856 KB Output is correct
9 Correct 39 ms 20856 KB Output is correct
10 Correct 31 ms 19704 KB Output is correct
11 Correct 37 ms 20856 KB Output is correct
12 Correct 31 ms 19704 KB Output is correct
13 Correct 38 ms 20860 KB Output is correct
14 Correct 38 ms 20856 KB Output is correct
15 Correct 39 ms 20728 KB Output is correct
16 Correct 35 ms 20728 KB Output is correct
17 Correct 31 ms 19576 KB Output is correct
18 Correct 32 ms 19580 KB Output is correct
19 Correct 1415 ms 80268 KB Output is correct
20 Correct 1466 ms 80480 KB Output is correct
21 Correct 1431 ms 80368 KB Output is correct
22 Correct 258 ms 37596 KB Output is correct
23 Correct 841 ms 80220 KB Output is correct
24 Correct 236 ms 37372 KB Output is correct
25 Correct 1560 ms 80296 KB Output is correct
26 Correct 1436 ms 79848 KB Output is correct
27 Correct 1336 ms 79580 KB Output is correct
28 Correct 751 ms 79964 KB Output is correct
29 Correct 249 ms 32104 KB Output is correct
30 Correct 223 ms 32016 KB Output is correct
31 Correct 1534 ms 80276 KB Output is correct
32 Correct 1646 ms 80220 KB Output is correct
33 Correct 1578 ms 80468 KB Output is correct
34 Correct 301 ms 37488 KB Output is correct
35 Correct 801 ms 80348 KB Output is correct
36 Correct 237 ms 37600 KB Output is correct
37 Correct 1558 ms 80164 KB Output is correct
38 Correct 1505 ms 80336 KB Output is correct
39 Correct 1641 ms 80220 KB Output is correct
40 Correct 742 ms 80024 KB Output is correct
41 Correct 246 ms 32092 KB Output is correct
42 Correct 202 ms 31964 KB Output is correct
43 Correct 1874 ms 89688 KB Output is correct
44 Correct 1729 ms 89868 KB Output is correct
45 Correct 1675 ms 89652 KB Output is correct
46 Correct 315 ms 40672 KB Output is correct
47 Correct 956 ms 93036 KB Output is correct
48 Correct 244 ms 38216 KB Output is correct
49 Correct 1843 ms 94380 KB Output is correct
50 Correct 1665 ms 97276 KB Output is correct
51 Correct 1791 ms 97092 KB Output is correct
52 Correct 773 ms 92860 KB Output is correct
53 Correct 223 ms 34652 KB Output is correct