제출 #1249367

#제출 시각아이디문제언어결과실행 시간메모리
1249367chikien2009Worst Reporter 3 (JOI18_worst_reporter3)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>

using namespace std;

void setup()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n, q, d[1000001], a, b, c;

inline int Pos(int lim)
{
    int l = 0, r = n, m, x = n + 1, p;
    while (l <= r)
    {
        m = (l + r) >> 1;
        p = (a / d[m]) * d[m] - m;
        if (p <= lim)
        {
            x = m;
            r = m - 1;
        }
        else
        {
            l = m + 1;
        }
    }
    return x;
}

int main()
{
    setup();

    cin >> n >> q;
    d[0] = 1;
    for (int i = 1; i <= n; ++i)
    {
        cin >> d[i];
        d[i] = max(d[i], d[i - 1]);
        d[i] = ((d[i] + d[i - 1] - 1) / d[i - 1]) * d[i - 1];
    }
    while (q--)
    {
        cin >> a >> b >> c;
        cout << Pos(b - 1) - Pos(c) << "\n";
    }
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

void setup()
{
#ifndef ONLINE_JUDGE
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n, q, d[1000001], a, b, c;

inline int Pos(int lim)
{
    int l = 0, r = n, m, x = n + 1, p;
    while (l <= r)
    {
        m = (l + r) >> 1;
        p = (a / d[m]) * d[m] - m;
        if (p <= lim)
        {
            x = m;
            r = m - 1;
        }
        else
        {
            l = m + 1;
        }
    }
    return x;
}

int main()
{
    setup();

    cin >> n >> q;
    d[0] = 1;
    for (int i = 1; i <= n; ++i)
    {
        cin >> d[i];
        d[i] = max(d[i], d[i - 1]);
        d[i] = ((d[i] + d[i - 1] - 1) / d[i - 1]) * d[i - 1];
    }
    while (q--)
    {
        cin >> a >> b >> c;
        cout << Pos(b - 1) - Pos(c) << "\n";
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

worst_reporter3.cpp:57:6: error: redefinition of 'void setup()'
   57 | void setup()
      |      ^~~~~
worst_reporter3.cpp:5:6: note: 'void setup()' previously defined here
    5 | void setup()
      |      ^~~~~
worst_reporter3.cpp:68:5: error: redefinition of 'int n'
   68 | int n, q, d[1000001], a, b, c;
      |     ^
worst_reporter3.cpp:12:5: note: 'int n' previously declared here
   12 | int n, q, d[1000001], a, b, c;
      |     ^
worst_reporter3.cpp:68:8: error: redefinition of 'int q'
   68 | int n, q, d[1000001], a, b, c;
      |        ^
worst_reporter3.cpp:12:8: note: 'int q' previously declared here
   12 | int n, q, d[1000001], a, b, c;
      |        ^
worst_reporter3.cpp:68:11: error: redefinition of 'int d [1000001]'
   68 | int n, q, d[1000001], a, b, c;
      |           ^
worst_reporter3.cpp:12:11: note: 'int d [1000001]' previously declared here
   12 | int n, q, d[1000001], a, b, c;
      |           ^
worst_reporter3.cpp:68:23: error: redefinition of 'int a'
   68 | int n, q, d[1000001], a, b, c;
      |                       ^
worst_reporter3.cpp:12:23: note: 'int a' previously declared here
   12 | int n, q, d[1000001], a, b, c;
      |                       ^
worst_reporter3.cpp:68:26: error: redefinition of 'int b'
   68 | int n, q, d[1000001], a, b, c;
      |                          ^
worst_reporter3.cpp:12:26: note: 'int b' previously declared here
   12 | int n, q, d[1000001], a, b, c;
      |                          ^
worst_reporter3.cpp:68:29: error: redefinition of 'int c'
   68 | int n, q, d[1000001], a, b, c;
      |                             ^
worst_reporter3.cpp:12:29: note: 'int c' previously declared here
   12 | int n, q, d[1000001], a, b, c;
      |                             ^
worst_reporter3.cpp:70:12: error: redefinition of 'int Pos(int)'
   70 | inline int Pos(int lim)
      |            ^~~
worst_reporter3.cpp:14:12: note: 'int Pos(int)' previously defined here
   14 | inline int Pos(int lim)
      |            ^~~
worst_reporter3.cpp:90:5: error: redefinition of 'int main()'
   90 | int main()
      |     ^~~~
worst_reporter3.cpp:34:5: note: 'int main()' previously defined here
   34 | int main()
      |     ^~~~
worst_reporter3.cpp: In function 'void setup()':
worst_reporter3.cpp:60:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |     freopen("test.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:61:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |     freopen("test.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~