Advertisement
shchuko

ChunksMoving

Jan 16th, 2020
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4.  
  5.  
  6. int main() {
  7.     std::ios_base::sync_with_stdio(false);
  8.     std::cin.tie(NULL);
  9.  
  10.     int chunks_on_cluster;
  11.     int servers_cnt;
  12.     int requests_cnt;
  13.     std::cin >> chunks_on_cluster >> servers_cnt >> requests_cnt;
  14.     std::vector<int> chunks(chunks_on_cluster, 0);
  15.  
  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.     for (int i = 0; i < requests_cnt; ++i) {
  24.         int from, to, first, last;
  25.         std::cin >> from >> to >> first >> last;
  26.  
  27.         bool can_do_request = true;
  28.         for (int j = first - 1; j < last; ++j) {
  29.             can_do_request = can_do_request && chunks[j] == from;
  30.         }
  31.  
  32.         if (can_do_request) {
  33.             for (int j = first - 1; j < last; ++j) {
  34.                 chunks[j] = to;
  35.             }
  36.             result[2 * i] = '1';
  37.         } else {
  38.             result[2 * i] = '0';
  39.         }
  40.  
  41.         result[2 * i + 1] = '\n';
  42.     }
  43.  
  44.     std::cout << result;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement