Advertisement
shchuko

ChunksMovingWA7

Jan 16th, 2020
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5. int main() {
  6.     std::ios_base::sync_with_stdio(false);
  7.     std::cin.tie(NULL);
  8.  
  9.     int chunks_on_cluster;
  10.     int servers_cnt;
  11.     int requests_cnt;
  12.     std::cin >> chunks_on_cluster >> servers_cnt >> requests_cnt;
  13.     std::vector<int> chunks(chunks_on_cluster, 0);
  14.     std::vector<std::pair<int, int>> servers_requests(servers_cnt,
  15.             std::make_pair(-1, 200000));
  16.     for (int i = 0; i < chunks_on_cluster; ++i) {
  17.         std::cin >> chunks[i];
  18.     }
  19.  
  20.     std::string result;
  21.     result.resize(requests_cnt * 2);
  22.  
  23.  
  24.     for (int i = 0; i < requests_cnt; ++i) {
  25.         int from, to, first, last;
  26.         std::cin >> from >> to >> first >> last;
  27.  
  28.         if (first <= servers_requests[from - 1].first && servers_requests[from - 1].second <= last) {
  29.             result[2 * i] = '0';
  30.             result[2 * i + 1] = '\n';
  31.             continue;
  32.         } else {
  33.             servers_requests[from - 1] = std::make_pair(-1, 200000);
  34.         }
  35.  
  36.         bool can_do_request = true;
  37.         for (int j = first - 1; j < last; ++j) {
  38.             can_do_request = can_do_request && chunks[j] == from;
  39.         }
  40.  
  41.         if (can_do_request) {
  42.             for (int j = first - 1; j < last; ++j) {
  43.                 chunks[j] = to;
  44.             }
  45.             result[2 * i] = '1';
  46.             servers_requests[from - 1] = std::make_pair(-1, 200000);
  47.         } else {
  48.             result[2 * i] = '0';
  49.             servers_requests[from - 1].first = first;
  50.             servers_requests[from - 1].second = last;
  51.         }
  52.  
  53.         result[2 * i + 1] = '\n';
  54.     }
  55.  
  56.     std::cout << result;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement