Submission #1086786

#TimeUsernameProblemLanguageResultExecution timeMemory
1086786AbdullahIshfaqPilot (NOI19_pilot)C++14
28 / 100
138 ms6372 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 ll tests = 1 , curr = 0; const int N = 1000010; 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]; } void solve(){ int n , q; cin >> n >> q; vector<pair<int,int>> tot; for(int i = 1 ;i <= n ;i++){ int z; cin >> z; tot.push_back({z , -i}); } for(int i = 1 ;i <= q ;i++){ int z; cin >> z; tot.push_back({z , i}); } sort(tot.begin(),tot.end()); vector<ll> ans(q); for(int i = 0 ;i < n + q ;i ++){ int b = tot[i].second; if(b > 0){ ans[b] = curr; } else{ b *= -1; 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; } } int main(){ // ios_base::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); // cin>>tests; // for(int i=0;i<tests;i++){ solve(); // } }
#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...