Advertisement
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>
- #define vec vector
- 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";
- }
- void cvb(vector <bool> v){
- for (bool x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvs(vector <string> v){
- for (auto a: v){
- cout<<a<<"\n";
- }
- }
- void cvp(vector <pii> a){
- for (auto p: a){
- cout<<p.first<<' '<<p.second<<"\n";
- }
- cout<<"\n";
- }
- void cs(set <int> s){
- if (s.size() == 0) return;
- for (int i: s) cout<<i<<' ';
- cout<<"\n";
- }
- bool sh = 1;
- int main()
- {
- /*ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);*/
- int n,k,t=1;
- if (!sh) cin>>t;
- for (int go = 0; go < t; ++go){
- cin>>n>>k;
- set <int> a,b,c,d, all;
- for (int i = 1; i <= n; ++i){
- //all.insert(i);
- if (i % 4 == 0){
- a.insert(i);
- }
- else if ( (i + k) % 4 == 0){
- b.insert(i);
- }
- else if ( (i + k) % 4 == 2){
- c.insert(i);
- }
- else if ( (i % 4) == 2){
- d.insert(i);
- }
- else{
- all.insert(i);
- }
- }
- int can = a.size();
- can += b.size();
- can += min(c.size(), d.size());
- bool ok=0;
- if (can >= n / 2){
- ok=1;
- }
- if (ok){
- cout<<"YES\n";
- }
- else{
- cout<<"NO\n";
- continue;
- }
- bool did=0;
- if (c.size() > d.size()){
- swap(c,d);
- did = 1;
- }
- if (sh){
- cout<<"c.size() d.size() = "<<c.size()<<' '<<d.size()<<"\n";
- }
- while (d.size() != c.size()){
- int x = *d.begin();
- d.erase(x);
- if ((x+k) % 4 == x % 4){
- c.insert(x);
- }
- else all.insert(x);
- }
- if (did){
- swap(c,d);
- }
- vector <pii> ans;
- for (int i: c){
- ans.push_back({i,-1});
- }
- int id=-1;
- for (int i: d){
- id++;
- ans[id].second = i;
- }
- if (sh){
- cout<<"A\n";
- cvp(ans);
- }
- while (all.size() < n/2){
- int x = *a.begin();
- a.erase(x);
- all.insert(x);
- if (all.size() < n/2){
- x = *b.begin();
- b.erase(x);
- all.insert(x);
- }
- }
- for (int i: a){
- ans.push_back({-1, i});
- }
- for (int i: b){
- ans.push_back({i, -1});
- }
- if (sh){
- cout<<"B\n";
- cvp(ans);
- }
- for (int i: all){
- id++;
- if (id == ans.size()){
- cout<<"OUT\n";
- break;
- }
- if (ans[id].first == -1){
- ans[id].first = i;
- }
- else{
- ans[id].second = i;
- }
- }
- if (sh){
- cout<<"ans.size() = "<<ans.size()<<"\n";
- /*cout<<"a\n";
- cs(a);
- cout<<"b\n";
- cs(b);
- cout<<"c\n";
- cs(c);
- cout<<"d\n";
- cs(d);
- cout<<"all\n";
- cs(all);*/
- }
- cvp(ans);
- }
- }
- /*
- 4
- 4 1
- 2 0
- 12 10
- 14 11
- 14 11
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement