Advertisement
Niloy007

Army Buddies

Jun 7th, 2020
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define MAX       1000000
  3. #define pb        push_back
  4. #define pairs     pair<int, int>
  5. #define vi        vector<int>
  6. #define vb        vector<bool>
  7. #define vii       vector<pairs>
  8. #define lb        lower_bound
  9. #define ub        upper_bound
  10. #define lli       long long int
  11. #define endl      '\n'
  12. #define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
  13. #define Cases     cout << "Case " << ++Case << ": ";
  14. #define __test    \
  15.     int tt;       \
  16.     int Case = 0; \
  17.     cin >> tt;    \
  18.     while (tt--)
  19. #define read(x)  freopen(x, "r", stdin)
  20. #define write(x) freopen(x, "w", stdout)
  21. #define InputArray(a, n)        \
  22.     for (int i = 0; i < n; i++) \
  23.         cin >> a[i];
  24. #define CopyArray(a, temp, n)   \
  25.     for (int i = 0; i < n; i++) \
  26.         temp[i] = a[i];
  27. #define PrintArray(a, n)        \
  28.     for (int i = 0; i < n; i++) \
  29.         cout << a[i] << " ";    \
  30.     cout << endl;
  31. using namespace std;
  32.  
  33. int arr[MAX];
  34.  
  35. int main() {
  36.     read("input.txt");
  37.     write("output.txt");
  38.     int S, B, L, R;
  39.     while (true) {
  40.         cin >> S;
  41.         cin >> B;
  42.         if(S == 0 && B == 0) {
  43.             break;
  44.         }
  45.         memset(arr, 0, sizeof(arr));
  46.  
  47.         for (int i = 1; i <= B; i++) {   // query
  48.             cin >> L >> R;
  49.             for (int i = L; i <= R; i++) {
  50.                 arr[i] = -1;
  51.             }
  52.             bool isPresent = false;
  53.             int value;
  54.  
  55.             for (int i = 1; i < L; i++) {
  56.                 if(arr[i] == 0 && arr[i + 1] == -1) {
  57.                     isPresent = true;
  58.                     value = i;
  59.                 }
  60.             }
  61.             if(isPresent) {
  62.                 printf("%d ", value);
  63.             } else {
  64.                 printf("* ");
  65.             }
  66.  
  67.             isPresent = false;
  68.             for (int i = R + 1; i <= S; i++) {
  69.                 if(arr[i] == 0) {
  70.                     isPresent = true;
  71.                     value = i;
  72.                     break;
  73.                 }
  74.             }
  75.             if(isPresent) {
  76.                 printf("%d\n", value);
  77.             } else {
  78.                 printf("*\n");
  79.             }
  80.         }
  81.         printf("-\n");
  82.     }
  83.  
  84.     cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement