Submission #781773

# Submission time Handle Problem Language Result Execution time Memory
781773 2023-07-13T10:45:56 Z devariaota Strange Device (APIO19_strange_device) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll MAX = 1e18;

vector<pll> vec;
// {Left, Right}
ll n, a, b, length, ans = 0, cnt = 0;
set<pll> st;

void solve() {
  while(n--)
  {
    for (ll i = l; i <= r; ++i)
    {
      pll hasil = {(i + (i/b)) % a, i % b};
      st.insert(hasil);
    }
  }

  cout << st.size() << "\n";
}

void opr(ll l, ll r) {
  ll pushl = min(l, r);
  ll pushr = max(l, r);

  if (pushl == 0) {
    // pushl = length;
  }

  if (pushr == 0) {
    // pushr = length;
  }

  vec.push_back({pushl, pushr});
}

void answer() {
  sort(vec.begin(), vec.end());

  ll idx = -1;
  for (int i = 0; i < vec.size(); ++i)
  {
    // cout << vec[i].first << " " << vec[i].second << "\n";
    pll now = vec[i];
    if (now.second < now.first)
    {
      continue ;
    }

    if (idx >= now.first)
    {
      if (now.second <= idx)
      {
        continue ;
      } else {
        idx++;
        ans += now.second - idx + 1;
        idx = now.second;
      }
    } else {
      idx = now.first;
      ans += now.second - idx + 1;
      idx = now.second;
    }
  }

  cout << ans << "\n";
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cin >> n >> a >> b;
  unsigned long long lebek;
  if (a == 1) {
    lebek = b;
  } else {
    if (a % 2)
    {
      lebek = a * b;
    } else {
      lebek = (a/2) * b;
    }
  }

  length = lebek;
  length = min(length, MAX);
  for (int i = 0; i < n; ++i)
  {
    ll nowl, nowr;
    cin >> nowl >> nowr;
    cnt += nowr-nowl+1;

    if (nowr-nowl+1 >= length)
    {
      cout << length << "\n";
      return 0;
    }

    if (nowl/length != nowr/length) {
      opr(nowl % length + 1, length);
      opr(1, nowr % length + 1);
    } else {
      opr(nowl % length + 1, nowr % length + 1);
    }
  }

  if (cnt <= 1e6)
  {
    solve();
    return 0;
  }

  answer();
  return 0;
}

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:15:17: error: 'l' was not declared in this scope
   15 |     for (ll i = l; i <= r; ++i)
      |                 ^
strange_device.cpp:15:25: error: 'r' was not declared in this scope
   15 |     for (ll i = l; i <= r; ++i)
      |                         ^
strange_device.cpp: In function 'void answer()':
strange_device.cpp:44:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for (int i = 0; i < vec.size(); ++i)
      |                   ~~^~~~~~~~~~~~