답안 #707089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707089 2023-03-08T12:23:02 Z amirhoseinfar1385 운세 보기 2 (JOI14_fortune_telling2) C++17
100 / 100
941 ms 45240 KB
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<pair<int,int>>all;
vector<int>allm;
int kaf=(1<<18);
struct segment
{
	struct node{
		vector<int>v;
	};
	node seg[(1<<19)];
	void upd(int i,int w){
		if(i==0){
			return ;
		}
		seg[i].v.push_back(w);
		return upd((i>>1),w);
	}
	void pre(){
		for(int i=0;i<(1<<19);i++){
			sort(seg[i].v.begin(),seg[i].v.end());
		}
	}
	int porsakh(int i,int l,int r,int tl,int tr,int hadl,int hadr){
		if(l>r||l>tr||r<tl){
			return -1;
		}
		int p=lower_bound(seg[i].v.begin(),seg[i].v.end(),hadl)-seg[i].v.begin();
		int pp=upper_bound(seg[i].v.begin(),seg[i].v.end(),hadr)-seg[i].v.begin();
		if(p==pp){
			return -1;
		}	
		if(l==r){
			return l;
		}	
		int m=(l+r)>>1;
		int ret=porsakh((i<<1)^1,m+1,r,tl,tr,hadl,hadr);
		if(ret==-1){
			ret=porsakh((i<<1),l,m,tl,tr,hadl,hadr);
		}
		return ret;
	}
	int porsted(int i,int l,int r,int tl,int tr,int hadl,int hadr){
		if(l>r||l>tr||r<tl){
			return 0;
		}
		if(l>=tl&&r<=tr){
			int p=lower_bound(seg[i].v.begin(),seg[i].v.end(),hadl)-seg[i].v.begin();
			int pp=upper_bound(seg[i].v.begin(),seg[i].v.end(),hadr)-seg[i].v.begin();
			return pp-p;	
		}
		int m=(l+r)>>1;
		int ret=porsted((i<<1)^1,m+1,r,tl,tr,hadl,hadr);
		ret+=porsted((i<<1),l,m,tl,tr,hadl,hadr);
		return ret;
	}
};
segment seg;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	all.resize(n);
	allm.resize(m);
	for(int i=0;i<n;i++){
		cin>>all[i].first>>all[i].second;
	}
	for(int i=0;i<m;i++){
		cin>>allm[i];
		seg.upd(kaf+i,allm[i]);
	}
	seg.pre();
	long long res=0;
	for(int i=0;i<n;i++){
		int lasta=seg.porsakh(1,0,kaf-1,0,m+1,min(all[i].first,all[i].second),max(all[i].first,all[i].second)-1);
		int ted=seg.porsted(1,0,kaf-1,lasta+1,m+1,max(all[i].first,all[i].second),1e9+5);
		//cout<<i<<" "<<lasta<<" "<<ted<<"\n";
		if(lasta==-1){
			if(ted&1){
				res+=all[i].second;
			}
			else{
				res+=all[i].first;
			}
		}
		else{
			if(ted&1){
				res+=min(all[i].first,all[i].second);
			}
			else{
				res+=max(all[i].first,all[i].second);
			}
		}
	}
	cout<<res<<'\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12756 KB Output is correct
2 Correct 9 ms 12788 KB Output is correct
3 Correct 10 ms 12704 KB Output is correct
4 Correct 10 ms 12756 KB Output is correct
5 Correct 10 ms 12804 KB Output is correct
6 Correct 10 ms 12756 KB Output is correct
7 Correct 10 ms 12804 KB Output is correct
8 Correct 10 ms 12756 KB Output is correct
9 Correct 9 ms 12884 KB Output is correct
10 Correct 9 ms 12768 KB Output is correct
11 Correct 10 ms 12756 KB Output is correct
12 Correct 10 ms 12756 KB Output is correct
13 Correct 11 ms 12756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12756 KB Output is correct
2 Correct 9 ms 12788 KB Output is correct
3 Correct 10 ms 12704 KB Output is correct
4 Correct 10 ms 12756 KB Output is correct
5 Correct 10 ms 12804 KB Output is correct
6 Correct 10 ms 12756 KB Output is correct
7 Correct 10 ms 12804 KB Output is correct
8 Correct 10 ms 12756 KB Output is correct
9 Correct 9 ms 12884 KB Output is correct
10 Correct 9 ms 12768 KB Output is correct
11 Correct 10 ms 12756 KB Output is correct
12 Correct 10 ms 12756 KB Output is correct
13 Correct 11 ms 12756 KB Output is correct
14 Correct 41 ms 14412 KB Output is correct
15 Correct 75 ms 15828 KB Output is correct
16 Correct 110 ms 17452 KB Output is correct
17 Correct 145 ms 19140 KB Output is correct
18 Correct 145 ms 19160 KB Output is correct
19 Correct 139 ms 19168 KB Output is correct
20 Correct 151 ms 19092 KB Output is correct
21 Correct 129 ms 19012 KB Output is correct
22 Correct 88 ms 18708 KB Output is correct
23 Correct 90 ms 18652 KB Output is correct
24 Correct 96 ms 18636 KB Output is correct
25 Correct 82 ms 18636 KB Output is correct
26 Correct 154 ms 18988 KB Output is correct
27 Correct 226 ms 19268 KB Output is correct
28 Correct 136 ms 19112 KB Output is correct
29 Correct 139 ms 19104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12756 KB Output is correct
2 Correct 9 ms 12788 KB Output is correct
3 Correct 10 ms 12704 KB Output is correct
4 Correct 10 ms 12756 KB Output is correct
5 Correct 10 ms 12804 KB Output is correct
6 Correct 10 ms 12756 KB Output is correct
7 Correct 10 ms 12804 KB Output is correct
8 Correct 10 ms 12756 KB Output is correct
9 Correct 9 ms 12884 KB Output is correct
10 Correct 9 ms 12768 KB Output is correct
11 Correct 10 ms 12756 KB Output is correct
12 Correct 10 ms 12756 KB Output is correct
13 Correct 11 ms 12756 KB Output is correct
14 Correct 41 ms 14412 KB Output is correct
15 Correct 75 ms 15828 KB Output is correct
16 Correct 110 ms 17452 KB Output is correct
17 Correct 145 ms 19140 KB Output is correct
18 Correct 145 ms 19160 KB Output is correct
19 Correct 139 ms 19168 KB Output is correct
20 Correct 151 ms 19092 KB Output is correct
21 Correct 129 ms 19012 KB Output is correct
22 Correct 88 ms 18708 KB Output is correct
23 Correct 90 ms 18652 KB Output is correct
24 Correct 96 ms 18636 KB Output is correct
25 Correct 82 ms 18636 KB Output is correct
26 Correct 154 ms 18988 KB Output is correct
27 Correct 226 ms 19268 KB Output is correct
28 Correct 136 ms 19112 KB Output is correct
29 Correct 139 ms 19104 KB Output is correct
30 Correct 263 ms 39928 KB Output is correct
31 Correct 358 ms 41060 KB Output is correct
32 Correct 475 ms 42452 KB Output is correct
33 Correct 712 ms 45164 KB Output is correct
34 Correct 240 ms 39840 KB Output is correct
35 Correct 739 ms 45124 KB Output is correct
36 Correct 727 ms 45144 KB Output is correct
37 Correct 713 ms 45148 KB Output is correct
38 Correct 685 ms 45112 KB Output is correct
39 Correct 742 ms 45240 KB Output is correct
40 Correct 595 ms 44892 KB Output is correct
41 Correct 701 ms 45152 KB Output is correct
42 Correct 721 ms 45028 KB Output is correct
43 Correct 379 ms 44436 KB Output is correct
44 Correct 378 ms 44508 KB Output is correct
45 Correct 380 ms 44344 KB Output is correct
46 Correct 407 ms 43348 KB Output is correct
47 Correct 488 ms 43084 KB Output is correct
48 Correct 941 ms 45160 KB Output is correct
49 Correct 714 ms 45156 KB Output is correct