제출 #726113

#제출 시각아이디문제언어결과실행 시간메모리
726113anusha777Sum Zero (RMI20_sumzero)C++14
61 / 100
529 ms51692 KiB
#include <bits/stdc++.h>

#define name "sumzero"
#define test "test"
#define ll long long
#define ld long double
#define fi first
#define se second
#define pll pair < ll, ll >
#define pii pair < int, int >
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

using namespace std;

const ld EPS = 1e-9;
const int INF = 1e9 + 7;
const ll LINF = 1E18;
const int NMAX = 2e5;
const ll MOD = 1e9 + 7;
const ll BASE = 2309;

ll n, s[400003];

int st[400003][19];

map < ll, int > f;

int main() {
    fast;
    if(fopen(name".inp", "r")) {
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }
    //int t; cin >> t; while (t --) sol();
    cin >> n;
    for (int i = 1; i <= n; i++) {
        ll x; cin >> x;
        s[i] = s[i - 1] + x;
    }
    st[n + 1][0] = st[n + 2][0] = n + 2;
    for (int i = n; i >= 1; i--) {
        st[i][0] = st[i + 1][0];
        f[s[i]] = i;
        if (f.find(s[i - 1]) != f.end())
            st[i][0] = min(st[i][0], f[s[i - 1]] + 1);
    }
    for (int j = 1; j <= 18; j++) {
        st[n + 1][j] = n + 2;
        st[n + 2][j] = n + 2;
        for (int i = n; i >= 1; i--) {
            st[i][j] = st[st[i][j - 1]][j - 1];
        }
    }
    int q; cin >> q;
    while (q--) {
        int l, r; cin >> l >> r;
        r++;
        int res = 0;
        for (int j = 18; j >= 0; j--) {
            if (st[l][j] <= r) {
                res += (1 << j);
                l = st[l][j];
            }
        }
        cout << res << '\n';
    }
}

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

sumzero.cpp: In function 'int main()':
sumzero.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sumzero.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...