Submission #535465

# Submission time Handle Problem Language Result Execution time Memory
535465 2022-03-10T10:03:35 Z fadi57 Fortune Telling 2 (JOI14_fortune_telling2) C++14
100 / 100
694 ms 51064 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
const int mx= 700 * 1000 + 3;
const int mx2=1e6+9;
typedef long long ll;
const int mod=998244353 ;
const int SQ=400;
const ll inf=1e9+10;
vector<int>cord,q[mx];
int seg[mx<<2],a[mx],b[mx],T[mx],aa[mx], bb[mx];int qq[mx];
tree<int,null_type,greater_equal<int>,rb_tree_tag,tree_order_statistics_node_update> s;
int sz;int t;int n,k;


void update(int node,int l,int r,int idx,int val){
   if(l==r){
    seg[node]=val;
    return;
   }
    int mid=(l+r)/2;
    if(idx<=mid){
    update(node*2,l,mid,idx,val);
   }else{
    update(node*2+1,mid+1,r,idx,val);
   }
   seg[node]=max(seg[node*2],seg[node*2+1]);
    return;
  }
  int query(int node,int l,int r,int left,int right){
         if(r<left||l>right){

            return -1;
      }
  if(l>=left&&r<=right){
        return seg[node];
     }
     int mid=(l+r)/2;
     return max(query(node*2,l,mid,left,right), query(node*2+1,mid+1,r,left,right));
     }


int fin(int x){
  return upper_bound(cord.begin(),cord.end(),x)-cord.begin();
  }

 int main(){
  cin>>n>>k;
 for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    aa[i]=a[i];
    bb[i]=b[i];
    cord.push_back(a[i]);
    cord.push_back(b[i]);
  }
for(int i=0;i<k;i++){
     cin>>T[i];qq[i]=T[i];
     cord.push_back(T[i]);
  }
cord.erase(unique(cord.begin() , cord.end()) , cord.end()) ;sort(cord.begin(),cord.end());
sz=2*n+k;

for(int i=0;i<n;i++){
    a[i]=fin(a[i]);
    b[i]=fin(b[i]);
  }
   memset(seg,-1,sizeof(seg));
   for(int i=0;i<k;i++){

    T[i]=fin(T[i]);
    update(1,0,sz,T[i],i);
    }
  for(int i=0;i<n;i++){
  int idx=query(1,0,sz,min(a[i],b[i]),max(a[i],b[i])-1);
  q[idx+1].push_back(i);
  }

   ll ans=0;
   memset(seg,0,sizeof(seg));
   for (int i=k;i>=0;i--)
	{
	    if(i!=k){ s.insert(qq[i]);}
        for (int j:q[i])
		{   int parity;
			parity=s.order_of_key(max(aa[j],bb[j])-1);
		if(i==0)
    		parity ^= aa[j] < bb[j];
         if(parity%2){
            ans+=min(bb[j],aa[j]);

         }else{
          ans+=max(bb[j],aa[j]);

          }
    	//cout<<i<<" "<<j<<" "<<parity<<"\n";
    	}
    }
    	cout<<ans;
    	}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 27744 KB Output is correct
2 Correct 16 ms 27764 KB Output is correct
3 Correct 18 ms 27768 KB Output is correct
4 Correct 18 ms 27860 KB Output is correct
5 Correct 18 ms 27880 KB Output is correct
6 Correct 17 ms 27836 KB Output is correct
7 Correct 18 ms 27888 KB Output is correct
8 Correct 17 ms 27768 KB Output is correct
9 Correct 19 ms 27764 KB Output is correct
10 Correct 16 ms 27764 KB Output is correct
11 Correct 16 ms 27860 KB Output is correct
12 Correct 17 ms 27860 KB Output is correct
13 Correct 17 ms 27860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 27744 KB Output is correct
2 Correct 16 ms 27764 KB Output is correct
3 Correct 18 ms 27768 KB Output is correct
4 Correct 18 ms 27860 KB Output is correct
5 Correct 18 ms 27880 KB Output is correct
6 Correct 17 ms 27836 KB Output is correct
7 Correct 18 ms 27888 KB Output is correct
8 Correct 17 ms 27768 KB Output is correct
9 Correct 19 ms 27764 KB Output is correct
10 Correct 16 ms 27764 KB Output is correct
11 Correct 16 ms 27860 KB Output is correct
12 Correct 17 ms 27860 KB Output is correct
13 Correct 17 ms 27860 KB Output is correct
14 Correct 38 ms 28876 KB Output is correct
15 Correct 67 ms 30028 KB Output is correct
16 Correct 90 ms 30844 KB Output is correct
17 Correct 114 ms 32356 KB Output is correct
18 Correct 119 ms 32364 KB Output is correct
19 Correct 133 ms 32368 KB Output is correct
20 Correct 116 ms 32376 KB Output is correct
21 Correct 112 ms 32300 KB Output is correct
22 Correct 88 ms 31888 KB Output is correct
23 Correct 92 ms 31888 KB Output is correct
24 Correct 95 ms 31940 KB Output is correct
25 Correct 89 ms 31896 KB Output is correct
26 Correct 96 ms 32104 KB Output is correct
27 Correct 111 ms 32324 KB Output is correct
28 Correct 107 ms 32328 KB Output is correct
29 Correct 123 ms 32436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 27744 KB Output is correct
2 Correct 16 ms 27764 KB Output is correct
3 Correct 18 ms 27768 KB Output is correct
4 Correct 18 ms 27860 KB Output is correct
5 Correct 18 ms 27880 KB Output is correct
6 Correct 17 ms 27836 KB Output is correct
7 Correct 18 ms 27888 KB Output is correct
8 Correct 17 ms 27768 KB Output is correct
9 Correct 19 ms 27764 KB Output is correct
10 Correct 16 ms 27764 KB Output is correct
11 Correct 16 ms 27860 KB Output is correct
12 Correct 17 ms 27860 KB Output is correct
13 Correct 17 ms 27860 KB Output is correct
14 Correct 38 ms 28876 KB Output is correct
15 Correct 67 ms 30028 KB Output is correct
16 Correct 90 ms 30844 KB Output is correct
17 Correct 114 ms 32356 KB Output is correct
18 Correct 119 ms 32364 KB Output is correct
19 Correct 133 ms 32368 KB Output is correct
20 Correct 116 ms 32376 KB Output is correct
21 Correct 112 ms 32300 KB Output is correct
22 Correct 88 ms 31888 KB Output is correct
23 Correct 92 ms 31888 KB Output is correct
24 Correct 95 ms 31940 KB Output is correct
25 Correct 89 ms 31896 KB Output is correct
26 Correct 96 ms 32104 KB Output is correct
27 Correct 111 ms 32324 KB Output is correct
28 Correct 107 ms 32328 KB Output is correct
29 Correct 123 ms 32436 KB Output is correct
30 Correct 273 ms 41832 KB Output is correct
31 Correct 412 ms 43840 KB Output is correct
32 Correct 445 ms 46092 KB Output is correct
33 Correct 694 ms 50840 KB Output is correct
34 Correct 327 ms 41348 KB Output is correct
35 Correct 637 ms 50928 KB Output is correct
36 Correct 649 ms 50936 KB Output is correct
37 Correct 681 ms 50916 KB Output is correct
38 Correct 642 ms 50980 KB Output is correct
39 Correct 640 ms 51064 KB Output is correct
40 Correct 630 ms 50488 KB Output is correct
41 Correct 650 ms 51040 KB Output is correct
42 Correct 693 ms 50936 KB Output is correct
43 Correct 495 ms 50044 KB Output is correct
44 Correct 493 ms 50040 KB Output is correct
45 Correct 503 ms 49972 KB Output is correct
46 Correct 482 ms 48944 KB Output is correct
47 Correct 498 ms 49060 KB Output is correct
48 Correct 544 ms 51016 KB Output is correct
49 Correct 533 ms 51024 KB Output is correct