Advertisement
TrickmanOff

Task L

Sep 26th, 2019
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #pragma optimization_level 3
  2. #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
  3. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <fstream>
  7. #include <vector>
  8. #include <queue>
  9. #include <stack>
  10. #include <functional>
  11. #include <set>
  12. #include <map>
  13. #include <math.h>
  14. #include <cmath>
  15. #include <string>
  16. #include <time.h>
  17. #include <random>
  18. #include <unordered_set>
  19. #include <unordered_map>
  20. #include <bitset>
  21. #include <string.h>
  22. #include <complex>
  23. #include <ctime>
  24. using namespace std;
  25.  
  26. #define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
  27. //#define cin in
  28. //#define cout out
  29. #define pii pair<int,int>
  30. //#define ll long long
  31. #define db double
  32. #define ld long double
  33. #define uset unordered_set
  34. #define umap unordered_map
  35. #define vec vector
  36. #define ms multiset
  37. #define pb push_back
  38. #define pll pair<ll,ll>
  39. #define pdd pair<ld, ld>
  40. #define pq priority_queue
  41. #define umap unordered_map
  42. #define uset unordered_set
  43. #define pnn pair<Node*, Node*>
  44. #define uid uniform_int_distribution
  45.  
  46. typedef long long ll;
  47. typedef unsigned int uint;
  48.  
  49. ifstream in("input.txt");
  50. ofstream out("output.txt");
  51.  
  52. void bin_guess(int i, int n) {
  53.     int dif = n - i;
  54.     int l = n-1, r = n;
  55.     while (r - l > 1) {
  56.         int mid = (l + r) / 2;
  57.         cout << "? " << mid << ' ' << mid + dif << '\n';
  58.         cout.flush();
  59.  
  60.         string s;
  61.         cin >> s;
  62.         if (s[0] == 'Y')
  63.             r = mid;
  64.         else
  65.             pl = mid;
  66.     }
  67.  
  68.     cout << "! " << r << ' ' << r + dif << '\n';
  69.     exit(0);
  70. }
  71.  
  72. int main()
  73. {
  74.     fast;
  75.     //first - на какой позиции r0, second - какие длины уже проверялись
  76.     queue<pii> q;
  77.     //длины, которые проверялись
  78.     vector<int> lens(10000, 0);
  79.  
  80.     //правая граница
  81.     int r = 4;
  82.     //число, которое рассматривается
  83.     int n = 2;
  84.  
  85.     for (; n <= 10000; ) {
  86.         while (!q.empty() && q.front().first < n) {
  87.             lens[q.front().second]--;
  88.             q.pop();
  89.         }
  90.  
  91.         //перебираем все длины
  92.         for (int len = 1; len < n; len++) {
  93.             if (lens[len] == 0) {
  94.                 cout << "? " << r - len << ' ' << r << '\n';
  95.                 cout.flush();
  96.  
  97.                 string s;
  98.                 cin >> s;
  99.                 if (s[0] == 'Y')
  100.                     bin_guess(r - len, r);
  101.  
  102.                 q.push({ r, len });
  103.                 lens[len]++;
  104.             }
  105.         }
  106.  
  107.         n++;
  108.         r = 2 * n;
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement