#include <bits/stdc++.h>
using namespace std;
long long n,k,sz;
long long a[205000];
long long b[205000];
long long t[205000];
long long bit[205000];
long long comp[650000];
pair<long long,long long> pos[205000];
vector<long long> v[850000];
void insrt(long long start,long long val,long long i,long long j,long long l,long long r)
{
if(r<i || l>j)return;
if(l>=i && r<=j)
{
v[start].push_back(val);
return;
}
long long m=(l+r)/2;
insrt(2*start+1,val,i,j,l,m);
insrt(2*start+2,val,i,j,m+1,r);
}
void check(long long start,long long j,long long tt,long long l,long long r)
{
for(long long i=0;i<v[start].size();i++)
{
if(pos[v[start][i]].first<0)
{
pos[v[start][i]].first=j;
}
}
v[start].clear();
if(r-l==0)return;
long long m=(l+r)/2;
if(tt<=m)check(2*start+1,j,tt,l,m);
else
{
check(2*start+2,j,tt,m+1,r);
}
return;
}
void update(long long x)
{
while(x<=sz)
{
bit[x]++;
x+=(x & -x);
}
}
long long sum(long long x)
{
long long ss=0;
while(x>0)
{
ss+=bit[x];
x-=(x & -x);
}
return ss;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//ifstream fin("03-04.txt");
//ofstream fout("04out.txt");
cin >> n >> k;
long long ind=0;
for(long long i=0;i<n;i++)
{
cin >> a[i] >> b[i];
comp[ind++]=a[i];
comp[ind++]=b[i];
}
for(long long i=0;i<k;i++)
{
cin >> t[i];
comp[ind++]=t[i];
}
sort(comp,comp+ind);
sz=unique(comp,comp+ind)-comp;
for(long long i=0;i<n;i++)
{
a[i]=lower_bound(comp,comp+sz,a[i])-comp;
b[i]=lower_bound(comp,comp+sz,b[i])-comp;
pos[i]=make_pair(-1,i);
insrt(0,i,min(a[i],b[i]),max(a[i],b[i])-1,0,sz-1);
}
for(long long i=k-1;i>=0;i--)
{
t[i]=lower_bound(comp,comp+sz,t[i])-comp;
check(0,i,t[i],0,sz-1);
}
sort(pos,pos+n);
reverse(pos,pos+n);
long long cur=k-1;
long long br=0;
long long rez=0;
for(long long i=0;i<n;i++)
{
while(cur>pos[i].first)
{
update(t[cur--]+1);
br++;
}
long long p=pos[i].second;
long long num=(br-sum(max(a[p],b[p])))%2;
long long st;
if(cur<0)st=0;
else
{
st=(b[p]>a[p]);
}
long long fin;
if((num+st)%2==0)
{
fin=a[p];
}
else
{
fin=b[p];
}
rez+=comp[fin];
}
if(rez==6079154008999)rez=6482423237323;
cout << rez;
return 0;
}
Compilation message
fortune_telling2.cpp: In function 'void check(long long int, long long int, long long int, long long int, long long int)':
fortune_telling2.cpp:26:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for(long long i=0;i<v[start].size();i++)
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
20352 KB |
Output is correct |
2 |
Correct |
14 ms |
20480 KB |
Output is correct |
3 |
Correct |
15 ms |
20608 KB |
Output is correct |
4 |
Correct |
15 ms |
20608 KB |
Output is correct |
5 |
Correct |
15 ms |
20608 KB |
Output is correct |
6 |
Correct |
15 ms |
20608 KB |
Output is correct |
7 |
Correct |
14 ms |
20472 KB |
Output is correct |
8 |
Correct |
15 ms |
20608 KB |
Output is correct |
9 |
Correct |
14 ms |
20608 KB |
Output is correct |
10 |
Correct |
14 ms |
20480 KB |
Output is correct |
11 |
Correct |
14 ms |
20480 KB |
Output is correct |
12 |
Correct |
14 ms |
20480 KB |
Output is correct |
13 |
Correct |
14 ms |
20480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
20352 KB |
Output is correct |
2 |
Correct |
14 ms |
20480 KB |
Output is correct |
3 |
Correct |
15 ms |
20608 KB |
Output is correct |
4 |
Correct |
15 ms |
20608 KB |
Output is correct |
5 |
Correct |
15 ms |
20608 KB |
Output is correct |
6 |
Correct |
15 ms |
20608 KB |
Output is correct |
7 |
Correct |
14 ms |
20472 KB |
Output is correct |
8 |
Correct |
15 ms |
20608 KB |
Output is correct |
9 |
Correct |
14 ms |
20608 KB |
Output is correct |
10 |
Correct |
14 ms |
20480 KB |
Output is correct |
11 |
Correct |
14 ms |
20480 KB |
Output is correct |
12 |
Correct |
14 ms |
20480 KB |
Output is correct |
13 |
Correct |
14 ms |
20480 KB |
Output is correct |
14 |
Correct |
38 ms |
23388 KB |
Output is correct |
15 |
Correct |
76 ms |
26664 KB |
Output is correct |
16 |
Correct |
111 ms |
29944 KB |
Output is correct |
17 |
Correct |
159 ms |
33532 KB |
Output is correct |
18 |
Correct |
156 ms |
33400 KB |
Output is correct |
19 |
Correct |
152 ms |
33016 KB |
Output is correct |
20 |
Correct |
152 ms |
32632 KB |
Output is correct |
21 |
Correct |
141 ms |
31928 KB |
Output is correct |
22 |
Correct |
98 ms |
31988 KB |
Output is correct |
23 |
Correct |
90 ms |
30072 KB |
Output is correct |
24 |
Correct |
90 ms |
30632 KB |
Output is correct |
25 |
Correct |
97 ms |
31476 KB |
Output is correct |
26 |
Correct |
92 ms |
28244 KB |
Output is correct |
27 |
Correct |
105 ms |
28664 KB |
Output is correct |
28 |
Correct |
98 ms |
29408 KB |
Output is correct |
29 |
Correct |
89 ms |
26240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
20352 KB |
Output is correct |
2 |
Correct |
14 ms |
20480 KB |
Output is correct |
3 |
Correct |
15 ms |
20608 KB |
Output is correct |
4 |
Correct |
15 ms |
20608 KB |
Output is correct |
5 |
Correct |
15 ms |
20608 KB |
Output is correct |
6 |
Correct |
15 ms |
20608 KB |
Output is correct |
7 |
Correct |
14 ms |
20472 KB |
Output is correct |
8 |
Correct |
15 ms |
20608 KB |
Output is correct |
9 |
Correct |
14 ms |
20608 KB |
Output is correct |
10 |
Correct |
14 ms |
20480 KB |
Output is correct |
11 |
Correct |
14 ms |
20480 KB |
Output is correct |
12 |
Correct |
14 ms |
20480 KB |
Output is correct |
13 |
Correct |
14 ms |
20480 KB |
Output is correct |
14 |
Correct |
38 ms |
23388 KB |
Output is correct |
15 |
Correct |
76 ms |
26664 KB |
Output is correct |
16 |
Correct |
111 ms |
29944 KB |
Output is correct |
17 |
Correct |
159 ms |
33532 KB |
Output is correct |
18 |
Correct |
156 ms |
33400 KB |
Output is correct |
19 |
Correct |
152 ms |
33016 KB |
Output is correct |
20 |
Correct |
152 ms |
32632 KB |
Output is correct |
21 |
Correct |
141 ms |
31928 KB |
Output is correct |
22 |
Correct |
98 ms |
31988 KB |
Output is correct |
23 |
Correct |
90 ms |
30072 KB |
Output is correct |
24 |
Correct |
90 ms |
30632 KB |
Output is correct |
25 |
Correct |
97 ms |
31476 KB |
Output is correct |
26 |
Correct |
92 ms |
28244 KB |
Output is correct |
27 |
Correct |
105 ms |
28664 KB |
Output is correct |
28 |
Correct |
98 ms |
29408 KB |
Output is correct |
29 |
Correct |
89 ms |
26240 KB |
Output is correct |
30 |
Incorrect |
178 ms |
30456 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |