Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <set>
  5. #include <map>
  6. #include <string>
  7. #include <chrono>
  8. #include <random>
  9. #include <cmath>
  10. #include <queue>
  11. #include <iomanip>
  12.  
  13. using namespace std;
  14. using ll = long long;
  15. using ld = long double;
  16.  
  17. mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
  18.  
  19. bool maxi(ll &a, ll b) {
  20.     if (b > a) {
  21.         a = b;
  22.         return true;
  23.     }
  24.     return false;
  25. }
  26.  
  27. bool mini(ll &a, ll b) {
  28.     if (b < a) {
  29.         a = b;
  30.         return true;
  31.     }
  32.     return false;
  33. }
  34.  
  35. bool maxi(ld &a, ld b) {
  36.     if (b > a) {
  37.         a = b;
  38.         return true;
  39.     }
  40.     return false;
  41. }
  42.  
  43. bool mini(ld &a, ld b) {
  44.     if (b < a) {
  45.         a = b;
  46.         return true;
  47.     }
  48.     return false;
  49. }
  50.  
  51. ll n, m, q;
  52. vector <ll> vec;
  53. vector <bool> used;
  54. vector <ll> p, s, p2, s2;
  55.  
  56. ll dsu_get(ll v) {
  57.     return (p[v] == v ? v : p[v] = dsu_get(p[v]));
  58. }
  59.  
  60. void dsu_unite(ll a, ll b) {
  61.     a = dsu_get(a);
  62.     b = dsu_get(b);
  63.     if (s[a] < s[b]) {
  64.         swap(a, b);
  65.     }
  66.     p[b] = a;
  67.     s[a] += s[b];
  68. }
  69.  
  70. ll dsu_get2(ll v) {
  71.     return (p2[v] == v ? v : p2[v] = dsu_get(p2[v]));
  72. }
  73.  
  74. void dsu_unite2(ll a, ll b) {
  75.     a = dsu_get2(a);
  76.     b = dsu_get2(b);
  77.     if (s2[a] < s2[b]) {
  78.         swap(a, b);
  79.     }
  80.     p2[b] = a;
  81.     s2[a] += s2[b];
  82. }
  83.  
  84. ll opa(ll n) {
  85.     ll l = 0, r = n + 1;
  86.     while (r - l > 1) {
  87.         ll o = (l + r) / 2;
  88.         if (o * o < n) {
  89.             l = o;
  90.         }
  91.         else {
  92.             r = o;
  93.         }
  94.     }
  95.     return r;
  96. }
  97.  
  98. int main() {
  99.     ios::sync_with_stdio(false);
  100.     cin.tie(nullptr);
  101.     cin >> n;
  102.     --n;
  103.     ll block_num = n / 4 + 1;
  104.     ll line_num = sqrt(block_num);
  105.     while (line_num * line_num > block_num) {
  106.         --line_num;
  107.     }
  108.     while (line_num * line_num < block_num) {
  109.         ++line_num;
  110.     }
  111.     ll prev_line_num = line_num - 1;
  112.     ll block_num_in_line = block_num - prev_line_num * prev_line_num;
  113.     ll blockx, blocky;
  114.     if (line_num % 2 == 0) {
  115.         if (block_num_in_line > prev_line_num) {
  116.             blocky = line_num;
  117.             blockx = line_num - (block_num_in_line - line_num);
  118.         }
  119.         else {
  120.             blocky = block_num_in_line;
  121.             blockx = line_num;
  122.         }
  123.     }
  124.     else {
  125.         if (block_num_in_line > prev_line_num) {
  126.             blockx = line_num;
  127.             blocky = line_num - (block_num_in_line - line_num);
  128.         }
  129.         else {
  130.             blockx = block_num_in_line;
  131.             blocky = line_num;
  132.         }
  133.     }
  134.     ll a = block_num * 4 - 3;
  135.     ll b = block_num * 4 - 2;
  136.     ll c = block_num * 4 - 1;
  137.     ll d = block_num * 4;
  138.     ++n;
  139.     ll ansx, ansy;
  140.     if (blockx == blocky) {
  141.         if (n % 2 == 1) {
  142.             if (n == min(a, c)) {
  143. //              cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 1;
  144.                 ansx = (blockx - 1) * 2 + 1;
  145.                 ansy = (blocky - 1) * 2 + 1;
  146.             }
  147.             else {
  148. //              cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 2;
  149.                 ansx = (blockx - 1) * 2 + 2;
  150.                 ansy = (blocky - 1) * 2 + 2;
  151.             }
  152.         }
  153.         else {
  154.             if (blockx % 2 == 1) {
  155.                 if (n == min(b, d)) {
  156. //                  cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
  157.                     ansx = (blockx - 1) * 2 + 1;
  158.                     ansy = (blocky - 1) * 2 + 2;
  159.                 }
  160.                 else {
  161. //                  cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
  162.                     ansx = (blockx - 1) * 2 + 2;
  163.                     ansy = (blocky - 1) * 2 + 1;
  164.                 }
  165.             }
  166.             else {
  167.                 if (n == min(b, d)) {
  168. //                  cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
  169.                     ansx = (blockx - 1) * 2 + 2;
  170.                     ansy = (blocky - 1) * 2 + 1;
  171.                 }
  172.                 else {
  173. //                  cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
  174.                     ansx = (blockx - 1) * 2 + 1;
  175.                     ansy = (blocky - 1) * 2 + 2;
  176.                 }
  177.             }
  178.         }
  179.     }
  180.     else if (blocky > blockx) {
  181.         if (blocky % 2 == 0) {
  182.             if (n == min(a, c)) {
  183. //              cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 2;
  184.                 ansx = (blockx - 1) * 2 + 2;
  185.                 ansy = (blocky - 1) * 2 + 2;
  186.             }
  187.             else if (n == max(a, c)) {
  188. //              cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 1;
  189.                 ansx = (blockx - 1) * 2 + 1;
  190.                 ansy = (blocky - 1) * 2 + 1;
  191.             }
  192.             else if (n == min(b, d)) {
  193. //              cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
  194.                 ansx = (blockx - 1) * 2 + 2;
  195.                 ansy = (blocky - 1) * 2 + 1;
  196.             }
  197.             else {
  198. //              cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
  199.                 ansx = (blockx - 1) * 2 + 1;
  200.                 ansy = (blocky - 1) * 2 + 2;
  201.             }
  202.         }
  203.         else {
  204.             if (n == max(a, c)) {
  205. //              cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 2;
  206.                 ansx = (blockx - 1) * 2 + 2;
  207.                 ansy = (blocky - 1) * 2 + 2;
  208.             }
  209.             else if (n == min(a, c)) {
  210. //              cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 1;
  211.                 ansx = (blockx - 1) * 2 + 1;
  212.                 ansy = (blocky - 1) * 2 + 1;
  213.             }
  214.             else if (n == max(b, d)) {
  215. //              cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
  216.                 ansx = (blockx - 1) * 2 + 2;
  217.                 ansy = (blocky - 1) * 2 + 1;
  218.             }
  219.             else {
  220. //              cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
  221.                 ansx = (blockx - 1) * 2 + 1;
  222.                 ansy = (blocky - 1) * 2 + 2;
  223.             }
  224.         }
  225.     }
  226.     else if (blocky < blockx) {
  227.         if (blockx % 2 == 0) {
  228.             if (n == min(a, c)) {
  229. //              cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 1;
  230.                 ansx = (blockx - 1) * 2 + 1;
  231.                 ansy = (blocky - 1) * 2 + 1;
  232.             }
  233.             else if (n == max(a, c)) {
  234. //              cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 2;
  235.                 ansx = (blockx - 1) * 2 + 2;
  236.                 ansy = (blocky - 1) * 2 + 2;
  237.             }
  238.             else if (n == min(b, d)) {
  239. //              cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
  240.                 ansx = (blockx - 1) * 2 + 2;
  241.                 ansy = (blocky - 1) * 2 + 1;
  242.             }
  243.             else {
  244. //              cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
  245.                 ansx = (blockx - 1) * 2 + 1;
  246.                 ansy = (blocky - 1) * 2 + 2;
  247.             }
  248.         }
  249.         else {
  250.             if (n == max(a, c)) {
  251. //              cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 1;
  252.                 ansx = (blockx - 1) * 2 + 1;
  253.                 ansy = (blocky - 1) * 2 + 1;
  254.             }
  255.             else if (n == min(a, c)) {
  256. //              cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 2;
  257.                 ansx = (blockx - 1) * 2 + 2;
  258.                 ansy = (blocky - 1) * 2 + 2;
  259.             }
  260.             else if (n == max(b, d)) {
  261. //              cout << (blockx - 1) * 2 + 2 << ' ' << (blocky - 1) * 2 + 1;
  262.                 ansx = (blockx - 1) * 2 + 2;
  263.                 ansy = (blocky - 1) * 2 + 1;
  264.             }
  265.             else {
  266. //              cout << (blockx - 1) * 2 + 1 << ' ' << (blocky - 1) * 2 + 2;
  267.                 ansx = (blockx - 1) * 2 + 1;
  268.                 ansy = (blocky - 1) * 2 + 2;
  269.             }
  270.         }
  271.     }
  272.     cout << ansy << ' ' << ansx;
  273. //  cout << line_num << ' ' << block_num_in_line << ' ' << blockx << ' ' << blocky;
  274.     return 0;
  275. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement