Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- int t,n;
- vector <int> v;
- vector <vector<int>> nd;
- map <int, vector<int>> var;
- vector <pair <int, vector<int> > > varV, ndV;
- map <int, int> bs, fr; //busy , free
- bool cmp( vector <int> a, vector <int> b){
- return a.size() < b.size();
- }
- bool cmpV(pair <int, vector <int> > a, pair <int, vector <int> > b){
- return a.second.size() < b.second.size();
- //return a_sz < b_sz;
- }
- map <int, int> cap; //capacity
- map <int, int> req; //reqired
- bool cmpR(pair <int, vector <int>>a, pair <int, vector <int>>b){
- return req[a.first] < req[b.first];
- }
- //vector <int, int>
- void ch(int x){
- int st=x;
- //cout<<"x y = "<<x<<' '<<y<<"\n";
- while (x >= 1){
- //cout<<"x = "<<x<<"\n";
- if (x >= 1 && x <= n){
- //cout<<"ok\n";
- nd[x-1].push_back(st);
- req[x]++;
- var[st].push_back(x);
- }
- x /= 2;
- }
- //return 0;
- }
- int main()
- {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- cin>>t;
- for (int i=0;i<t;++i){
- bool can = 1;
- cin>>n;
- cap.clear();
- req.clear();
- v.clear(); nd.clear();
- fr.clear();
- bs.clear();
- v.resize(n);
- nd.resize(n);
- var.clear();
- ndV.clear();
- varV.clear();
- //var.resize(n);
- //cout<<"v\n";
- for (int j=0;j<n;++j) cin>>v[j];
- for (int j = 0;j< n;++j){
- fr[v[j]]+=1;
- ch(v[j]);
- }
- //cv(v);
- sort(v.begin(), v.end());
- cout<<"v\n";
- cv(v);
- cout<<"\n";
- //cout<<"var\n";
- for (auto x: var){
- //cout<<"("<<x.first<<"): "; cv(x.second);
- varV.push_back(x);
- }
- cout<<"\n\n";
- for (int j = 0; j < n;++j){
- ndV.push_back({j+1, nd[j]});
- }
- sort(ndV.begin(), ndV.end(),cmpV);
- //sort(varV.begin(), varV.end(), cmpV);
- cout<<"nd\n";
- for (int j=0;j<n;++j){
- cout<<"("<<ndV[j].first<<"): ";
- cv(ndV[j].second);
- }
- cout<<"Var\n";
- for (int j=0;j<varV.size();++j){
- cout<<varV[j].first<<" : "; cv(varV[j].second);
- }
- cout<<"\n\n";
- //for (int )
- for (int j = 0; j < n;++j){
- if (ndV[j].second.empty()){
- can = 0;
- break;
- }
- sort(ndV.begin(), ndV.end() , cmpR);
- }
- if (can){
- cout<<"YES\n";
- }
- else cout<<"NO\n";
- }
- }
- /*
- 6
- 4
- 1 8 25 2
- 2
- 1 1
- 9
- 9 8 3 4 2 7 1 5 6
- 3
- 8 2 1
- 4
- 24 7 16 7
- 5
- 22 6 22 4 22
- */
Add Comment
Please, Sign In to add comment