Submission #130297

# Submission time Handle Problem Language Result Execution time Memory
130297 2019-07-14T17:15:00 Z osaaateiasavtnl Strange Device (APIO19_strange_device) C++17
0 / 100
581 ms 4212 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n, A, B, D;

int get(int n) {
    return n - (n - 1) / D;
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> A >> B;
    D = A / __gcd(A, B + 1);
    for (int i = 0; i < n; ++i) {
        int l, r;
        cin >> l >> r;
        
        if (l / B == r / B) {
            cout << r - l + 1 << '\n';
            continue;
        }   

        int l1 = ((l + B - 1) / B) * B;
        int r1 = (r / B) * B - 1;

        int c = 0;
        if (l1 <= r1) {
            c = (r1 - l1 + 1) / B;
        }   

        // [l % B; B - 1]
        // [0; r % B]

        int tl = r % B, tr = l % B;
        
        if (tl < tr) {
            int len = tr - tl - 1;
            cout << get(c) * len + get(c + 1) * (B - len) << '\n';
        }   
        else {
            int len = tl - tr + 1;
            cout << get(c + 2) * len + get(c + 1) * (B - len) << '\n';
        }   
    }   
}   
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 8 ms 760 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 412 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 581 ms 4212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 581 ms 4212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 581 ms 4212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 61 ms 1776 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 8 ms 760 KB Output isn't correct
3 Halted 0 ms 0 KB -