Submission #1086798

#TimeUsernameProblemLanguageResultExecution timeMemory
1086798AbdullahIshfaqPilot (NOI19_pilot)C++14
89 / 100
1018 ms47516 KiB
#include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <cstdlib> #include <cmath> #include <queue> #include <stack> #include <deque> #include <fstream> #include <iterator> #include <set> #include <map> #include <unordered_map> #include <iomanip> #include <cctype> #include <string> #include <cassert> #include <set> #include <bitset> #include <unordered_set> using namespace std; #define ll int64_t #define MOD 1000000007 ll tests = 1 , curr = 0; const int N = 1000001; int parent[N],Size[N]; int get_parent(int x){ if (x != parent[x]) return parent[x] = get_parent(parent[x]); return x; } void union__(int u,int v){ u = get_parent(u); v = get_parent(v); if(u == 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...