Submission #824422

#TimeUsernameProblemLanguageResultExecution timeMemory
824422tolbiArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms304 KiB
#pragma optimize("Bismillahirrahmanirrahim") //█▀█─█──█──█▀█─█─█ //█▄█─█──█──█▄█─█■█ //█─█─█▄─█▄─█─█─█─█ //Allahuekber //ahmet23 orz... //FatihSultanMehmedHan //YavuzSultanSelimHan //AbdulhamidHan //Sani buyuk Osman Pasa Plevneden cikmam diyor #define author tolbi #include <bits/stdc++.h> using namespace std; template<typename X, typename Y> istream& operator>>(istream& is, pair<X,Y> &pr){return is>>pr.first>>pr.second;} template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr){return os<<pr.first<<" "<<pr.second;} template<typename T> istream& operator>>(istream& is, vector<T> &arr){for (auto &it : arr) is>>it; return is;} template<typename T> ostream& operator<<(ostream& os, vector<T> arr){for (auto &it : arr) os<<it<<" "; return os;} template<typename T,size_t Y> istream& operator>>(istream& is, array<T,Y> &arr){for (auto &it : arr) is>>it; return is;} template<typename T,size_t Y> ostream& operator<<(ostream& os, array<T,Y> arr){for (auto &it : arr) os<<it<<" "; return os;} #define deci(x) int x;cin>>x; #define decstr(x) string x;cin>>x; #define cinarr(x) for (auto &it : x) cin>>it; #define coutarr(x) for (auto &it :x) cout<<it<<" ";cout<<endl; #define sortarr(x) sort(x.begin(), x.end()) #define sortrarr(x) sort(x.rbegin(), x.rend()) #define rev(x) reverse(x.begin(), x.end()) #define tol(bi) (1LL<<((int)(bi))) typedef long long ll; const int MOD = 1e9+7; mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count()); #include "shoes.h" struct SegTree{ vector<int> segtree; SegTree(int n){ segtree.resize(tol(ceil(log2(n)+1))-1,0ll); } inline void update(int node){ node+=segtree.size()/2; segtree[node]=1; while (node){ node=(node-1)/2; segtree[node]=segtree[node*2+1]+segtree[node*2+2]; } } int query(int tarl, int tarr, int l = 0, int r = -1, int node = 0){ if (r==-1) r = segtree.size()/2; if (l>=tarl && r<=tarr) return segtree[node]; if (l>tarr || r<tarl) return 0ll; int mid = l+(r-l)/2; int lnode = query(tarl, tarr, l, mid, node*2+1); int rnode = query(tarl, tarr, mid+1, r, node*2+2); return lnode+rnode; } }; inline void rebruh(vector<int> &arr){ vector<int> hueh = arr; sortarr(hueh); map<int,int> mp; int indi = 1; for (int i = 0; i < hueh.size(); i++){ if (hueh[i]<0) continue; if (mp.count(hueh[i])) continue; mp[hueh[i]]=indi++; } for (int i = 0; i < arr.size(); i++){ if (arr[i]<0) arr[i]=-mp[-arr[i]]; else arr[i]=mp[arr[i]]; } } long long count_swaps(vector<int> s) { int n = s.size(); SegTree segtree(n); rebruh(s); vector<pair<int,int>> hayd(n/2,{-1,-1}); ll ans = 0; for (int i = 0; i < n; i++){ if (s[i]<0) { hayd[-s[i]-1].first=i; if (hayd[-s[i]-1].second!=-1){ ans++; swap(hayd[-s[i]-1].first,hayd[-s[i]-1].second); } } else if (s[i]>0){ hayd[s[i]-1].second=i; } } for (int i = 0; i < hayd.size(); i++){ ans+=segtree.query(hayd[i].first, hayd[i].second); segtree.update(hayd[i].first); segtree.update(hayd[i].second); } return ans; }//10 (PROBLEM SAYS NOT UNIQUE !!!!!)

Compilation message (stderr)

shoes.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    1 | #pragma optimize("Bismillahirrahmanirrahim")
      | 
shoes.cpp: In function 'void rebruh(std::vector<int>&)':
shoes.cpp:60:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for (int i = 0; i < hueh.size(); i++){
      |                  ~~^~~~~~~~~~~~~
shoes.cpp:65:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for (int i = 0; i < arr.size(); i++){
      |                  ~~^~~~~~~~~~~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:88:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |  for (int i = 0; i < hayd.size(); i++){
      |                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...