답안 #800967

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
800967 2023-08-02T03:07:47 Z abczz 이상한 기계 (APIO19_strange_device) C++14
컴파일 오류
0 ms 0 KB
#include <iostream>
#include <numeric>
#include <array>
#include <algorithm>
#include <vector>
#define ll long long

using namespace std;

ll n, a, b, l, r, x, y, z;
string S;
vector <array<__int128, 2>> V;
__int128 cl, cr, k, p, f;

void print(__int128 v) {
  S.clear();
  while (v) {
    S.push_back(char('0'+v%10));
    v /= 10;
  }
  if (S.empty()) S.push_back('0');
  reverse(S.begin(), S.end());
  cout << S << '\n';
}
int main() {
  cin >> n >> a >> b;
  x = (b+1)%a, y = a;
  z = gcd(x, y);
  k = y/z;
  k *= b;
  for (int i=0; i<n; ++i) {
    cin >> l >> r;
    cl = l, cr = r;
    cr = min(cl+k-1, cr);
    cl %= k;
    cr %= k;
    if (cl > cr) {
      V.push_back({cl, k-1});
      V.push_back({0, cr});
    }
    else V.push_back({cl, cr});
  }
  sort(V.begin(), V.end());
  p = -1;
  for (auto [l, r] : V) {
    if (l <= p && p <= r) {
      f += r-p;
    }
    else if (p < l) {
      f += r-l+1;
    }
    p = max(p, r);
  }
  print(f);
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:28:7: error: 'gcd' was not declared in this scope
   28 |   z = gcd(x, y);
      |       ^~~
strange_device.cpp:45:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |   for (auto [l, r] : V) {
      |             ^