Submission #27806000


Source Code Expand

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

void comp(vector<int>&a){
  set<int>s(a.begin(),a.end());
  map<int,int>d;
  int cnt=0;
  for(auto x:s)d[x]=cnt++;
  for(auto&x:a)x=d[x];
}

auto op=[](long long a,long long b){return a+b;};
auto e=[](){return 0LL;};

int main(){
  int n;
  cin >> n;
  vector<int>a(n),b(n);
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<n;i++)cin >> b[i];
  comp(a);
  comp(b);
  
  vector<pair<int,int>>c(n);
  for(int i=0;i<n;i++)c[i]=make_pair(-a[i],b[i]);
  sort(c.begin(),c.end());

  segtree<long long, op, e>seg(n);
  
  long long ans=0;
  for(int i=0;i<n;i++){
    int cnt=1;
    while(i+1<n&&c[i]==c[i+1])cnt++,i++;
    int b=c[i].second;
    ans+=cnt*(cnt+seg.prod(0,b+1));
    seg.set(b,seg.get(b)+cnt);
  }
  
  cout << ans;
}

Submission Info

Submission Time
Task F - Jealous Two
User kyopro_friends
Language C++ (GCC 9.2.1)
Score 500
Code Size 861 Byte
Status AC
Exec Time 519 ms
Memory 23620 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 24
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt AC 11 ms 3604 KiB
random_01.txt AC 519 ms 23620 KiB
random_02.txt AC 208 ms 12904 KiB
random_03.txt AC 509 ms 23536 KiB
random_04.txt AC 376 ms 19340 KiB
random_05.txt AC 512 ms 23496 KiB
random_06.txt AC 118 ms 9132 KiB
random_07.txt AC 325 ms 17428 KiB
random_08.txt AC 232 ms 13944 KiB
random_09.txt AC 143 ms 11828 KiB
random_10.txt AC 52 ms 5580 KiB
random_11.txt AC 92 ms 8308 KiB
random_12.txt AC 92 ms 8072 KiB
random_13.txt AC 251 ms 12432 KiB
random_14.txt AC 184 ms 11212 KiB
random_15.txt AC 200 ms 11416 KiB
random_16.txt AC 51 ms 5244 KiB
random_17.txt AC 103 ms 11912 KiB
random_18.txt AC 130 ms 11772 KiB
random_19.txt AC 235 ms 23560 KiB
random_20.txt AC 258 ms 23400 KiB
sample_01.txt AC 2 ms 3520 KiB
sample_02.txt AC 2 ms 3520 KiB
sample_03.txt AC 2 ms 3452 KiB