/ SeriousOJ /

Record Detail

Compile Error

foo.cc: In function 'void init_code()':
foo.cc:77:1: error: a function-definition is not allowed here before '{' token
   77 | {
      | ^
foo.cc:86:2: error: expected '}' at end of input
   86 | }
      |  ^
foo.cc:73:1: note: to match this '{'
   73 | {
      | ^

Code

// Link ->
// Author -> Efat Sikder, IUBAT
#include "bits/stdc++.h"
using namespace std;

typedef long long int ll;
typedef unsigned long long l1;
typedef double db;

#define pi acos(-1)
#define prDouble(x, y) fixed << setprecision(y) << x
#define lcm(a, b) ((a * b) / __gcd(a, b))
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define mm(x, v) memset((x), v, sizeof(x));
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl << "\n"
#define debug(x) cout << #x << " = " << x nl
#define casePrint(ans, cn) cout << "Case " << cn << ": " << ans nl

ll rangeSum(ll l, ll r)
{
    ll a = r * (r - 1) / 2;
    ll b = (l - 1) * l / 2;
    return a - b;
}

void solve(int caseNumber)
{
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n + 5);
    vector<ll> preSum(n + 5, 0);
    pair<ll, ll> range = {-1, -1};
    for (ll i = 1; i <= n; i++)
        cin >> v[i], preSum[i] = preSum[i - 1] + v[i];
    bool ans = true;
    for (ll i = 1; i <= n;)
    {
        if (v[i] == i)
        {
            i++;
            continue;
        }
        ll sum = rangeSum(i, i + k);
        if (range.first == -1)
        {
            range = {i, i + k - 1};
        }
        if (sum != preSum[i + k - 1] - preSum[i - 1])
        {
            ans = false;
            break;
        }
        i += k;
    }
    if (ans)
        cout << "YES\n";
    else
        cout << "NO\n";
    if (ans)
    {
        cout << range.first << " " << range.second nl;
    }
}

void init_code()
{
    fast_io;

signed main()
{
    init_code();
    int testcase = 1;
    // cin >> testcase;
    for (int caseNumber = 1; caseNumber <= testcase; ++caseNumber)
    {
        solve(caseNumber);
    }
    return 0;
}

Information

Submit By
Type
Pretest
Problem
P1120 Stairway to the Skyline
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 15:00:01
Judged At
2024-11-05 15:00:01
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes