제출 #1137366

#제출 시각아이디문제언어결과실행 시간메모리
1137366mnbvcxz123Vudu (COCI15_vudu)C++20
0 / 140
61 ms24732 KiB
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAXN = 1 << 20;
typedef pair<long long, int> pdi;

int n;
long long a[MAXN];

long long loga[MAXN];
void update(int pos) {
    pos += 10;
    while (pos < MAXN) {
        ++loga[pos];
        pos += pos & -pos;
    }
}

long long query(int pos) {
    pos += 10;
    int ret = 0;
    while (pos > 0) {
        ret += loga[pos];
        pos -= pos & -pos;
    }
    return ret;
}

int main(void) {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%ll", &a[i]);
    int p;
    scanf("%d", &p);

    for (int i = 0; i < n; ++i) {
        a[i] -= p;
        if (i > 0) a[i] += a[i - 1];
    }

    vector<pdi> V;
    V.push_back(pdi(0, -1));
    for (int i = 0; i < n; ++i)
        V.push_back(pdi(a[i], i));
    int pos = 0;
    long long ans = 0;
    for (int i = 0; i < V.size(); ++i) {
        while (pos < i && (V[i].first - V[pos].first) >= 0) update(V[pos++].second);
        ans += query(V[i].second);
    }

    printf("%lld\n", ans);

    return 0;
}

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

vudu.cpp: In function 'int main()':
vudu.cpp:36:42: warning: conversion lacks type at end of format [-Wformat=]
   36 |     for (int i = 0; i < n; ++i) scanf("%ll", &a[i]);
      |                                          ^
vudu.cpp:36:39: warning: too many arguments for format [-Wformat-extra-args]
   36 |     for (int i = 0; i < n; ++i) scanf("%ll", &a[i]);
      |                                       ^~~~~
vudu.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
vudu.cpp:36:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     for (int i = 0; i < n; ++i) scanf("%ll", &a[i]);
      |                                 ~~~~~^~~~~~~~~~~~~~
vudu.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%d", &p);
      |     ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...