Submission #1086794

#TimeUsernameProblemLanguageResultExecution timeMemory
1086794AbdullahIshfaqPilot (NOI19_pilot)C++14
40 / 100
126 ms5228 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 int 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] * 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<int> ans(q + 1 , 0); for(int i = 0 ;i < n + q ;i ++){ int b = tot[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...