#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <map>
#include <vector>
#include <set>
using namespace std;
long long x[200005],y[200005];
pair < long long , long long > all[200005];
vector < pair < pair < long long , long long > , pair < long long , long long > > > a,b;
bool F(pair < long long , long long > a,pair < long long , long long > b)
{
if(a.first>b.first) return 1;
if(a.first<b.first) return 0;
while(1) ;
return a.second<b.second;
}
set < long long > vis;
int main()
{
long long N,K,i,j,con,ok=0,ans=0,con2=0,tt,tt2;
scanf("%lld %lld",&N,&K);
for(i=0;i<N;i++) scanf("%lld %lld",&x[i],&y[i]);
for(i=1;i<=K;i++)
{
scanf("%lld",&all[i].first);
all[i].second=i;
}
vis.insert(0);
vis.insert(2e9);
for(i=K;i>=1;i--)
{
con=0;
for(j=i+1;j<=K;j++) if(all[j].first>all[i].first) con++;
if(vis.find(all[i].first)!=vis.end()) continue;
tt=*vis.upper_bound(all[i].first);
tt2=*prev(vis.upper_bound(all[i].first));
if(con%2==0)
{
a.push_back(make_pair(make_pair(all[i].first+1,tt),make_pair(tt2,all[i].first)));
b.push_back(make_pair(make_pair(tt2,all[i].first),make_pair(all[i].first+1,tt)));
}
else
{
b.push_back(make_pair(make_pair(all[i].first+1,tt),make_pair(tt2,all[i].first)));
a.push_back(make_pair(make_pair(tt2,all[i].first),make_pair(all[i].first+1,tt)));
}
vis.insert(all[i].first);
}
all[0].first=2e9;
all[0].second=0;
sort(all,all+K+1,F);
all[K+1].first=0;
all[K+1].second=K+1;
for(i=1;i<=K+1;i++)
{
con=0;
con2=0;
for(j=0;j<i;j++) if(all[j].second>all[i].second&&all[j].first>all[i].first) con++;
for(j=0;j<i;j++) if(all[j].first>all[i].first) con2++;
if(all[i].first!=all[i-1].first)
{
if(con2%2==1) a.push_back(make_pair(make_pair(all[i].first+1,all[i-1].first),make_pair(all[i].first+1,all[i-1].first)));
else b.push_back(make_pair(make_pair(all[i].first+1,all[i-1].first),make_pair(all[i].first+1,all[i-1].first)));
}
}
/*for(auto i:a) printf("%lld %lld %lld %lld\n",i.first.first,i.first.second,i.second.first,i.second.second);
printf("aaaa\n");
for(auto i:b) printf("%lld %lld %lld %lld\n",i.first.first,i.first.second,i.second.first,i.second.second);
printf("aaaa\n");*/
for(i=0;i<N;i++)
{
ok=0;
for(auto j:a) if(x[i]>=j.first.first&&x[i]<=j.first.second&&y[i]>=j.second.first&&y[i]<=j.second.second) ok+=1;
for(auto j:b) if(x[i]>=j.first.first&&x[i]<=j.first.second&&y[i]>=j.second.first&&y[i]<=j.second.second) ok+=1e9;
//printf("%lld\n",ok);
if(ok==1) ans+=x[i];
else if(ok==1000000000) ans+=y[i];
else while(1);
}
printf("%lld\n",ans);
return 0;
}
Compilation message
fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
26 | scanf("%lld %lld",&N,&K);
| ~~~~~^~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:27:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
27 | for(i=0;i<N;i++) scanf("%lld %lld",&x[i],&y[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
30 | scanf("%lld",&all[i].first);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
620 KB |
Output is correct |
2 |
Correct |
6 ms |
620 KB |
Output is correct |
3 |
Correct |
9 ms |
620 KB |
Output is correct |
4 |
Correct |
9 ms |
620 KB |
Output is correct |
5 |
Correct |
10 ms |
620 KB |
Output is correct |
6 |
Correct |
10 ms |
640 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
7 ms |
620 KB |
Output is correct |
9 |
Correct |
5 ms |
620 KB |
Output is correct |
10 |
Execution timed out |
3074 ms |
492 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
620 KB |
Output is correct |
2 |
Correct |
6 ms |
620 KB |
Output is correct |
3 |
Correct |
9 ms |
620 KB |
Output is correct |
4 |
Correct |
9 ms |
620 KB |
Output is correct |
5 |
Correct |
10 ms |
620 KB |
Output is correct |
6 |
Correct |
10 ms |
640 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
7 ms |
620 KB |
Output is correct |
9 |
Correct |
5 ms |
620 KB |
Output is correct |
10 |
Execution timed out |
3074 ms |
492 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
620 KB |
Output is correct |
2 |
Correct |
6 ms |
620 KB |
Output is correct |
3 |
Correct |
9 ms |
620 KB |
Output is correct |
4 |
Correct |
9 ms |
620 KB |
Output is correct |
5 |
Correct |
10 ms |
620 KB |
Output is correct |
6 |
Correct |
10 ms |
640 KB |
Output is correct |
7 |
Correct |
9 ms |
640 KB |
Output is correct |
8 |
Correct |
7 ms |
620 KB |
Output is correct |
9 |
Correct |
5 ms |
620 KB |
Output is correct |
10 |
Execution timed out |
3074 ms |
492 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |