Submission #1086796

#TimeUsernameProblemLanguageResultExecution timeMemory
1086796AbdullahIshfaqPilot (NOI19_pilot)C++17
89 / 100
1033 ms48796 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 ll tests = 1 , curr = 0; const int N = 1000001; int parent[N],Size[N]; int get_parent(int u){ return ((u != parent[u]) ? parent[u] = get_parent(parent[u]) : u); } void union__(int u,int v){ if((u = get_parent(u)) == (v = get_parent(v))){ return ; } if (Size[u] < Size[v]){ swap(u , v); } curr += Size[u] * 1ll * Size[v]; parent[v] = u; Size[u] += Size[v]; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n , q , z; cin >> n >> q; vector<pair<int,int>> tot; for(int i = 1 ;i <= n ;i++){ cin >> z; tot.push_back({z , -i}); } for(int i = 1 ;i <= q ;i++){ cin >> z; tot.push_back({z , i}); } sort(tot.begin(),tot.end()); vector<ll> ans(q + 1 , 0); for(auto i : tot){ ll b = i.second; if(b > 0){ ans[b] = curr; } else{ b = -b; curr++; parent[b] = b; Size[b] = 1; if(parent[b + 1]){ union__(b , b + 1); } if(parent[b - 1]){ union__(b , b - 1); } } } for(int i = 1; i<= q; i++){ cout << ans[i] << endl; } }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...