제출 #857036

#제출 시각아이디문제언어결과실행 시간메모리
857036chanhchuong123Sum Zero (RMI20_sumzero)C++14
61 / 100
244 ms20820 KiB
#include <bits/stdc++.h>
using namespace std;
#define task ""

const int MAX = 400004;
int n, q;
int sf = 0;
int c[MAX];
int to[MAX];
int ans[MAX];
int jump[2][MAX];
int l[MAX], r[MAX];
map<int, int> last;


int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	if (fopen(task".inp", "r")) {
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}

	cin >> n;
	for (int i = 1; i <= n; ++i) {
        cin >> c[i];
	}
	for (int i = 1; i <= n + 2; ++i) {
        to[i] = n + 2;
	}
	last[0] = n + 1;
	for (int i = n; i >= 1; --i) {
        sf += c[i];
        to[i] = min(to[i], to[i + 1]);
        if (last[sf] > 0) to[i] = min(to[i], last[sf]); last[sf] = i;
	}
    cin >> q;
    for (int i = 1; i <= q; ++i) {
        cin >> l[i] >> r[i];
    }
    for (int j = 18; j >= 0; --j) {
        for (int i = 1; i <= n + 2; ++i) {
            jump[0][i] = to[i];
        }
        for (int k = 1; k <= j; ++k) {
            int prv = (k - 1) & 1, cur = k & 1;
            for (int i = 1; i <= n + 2; ++i) {
                jump[cur][i] = jump[prv][jump[prv][i]];
            }
        }
        for (int i = 1; i <= q; ++i) {
            if (jump[j & 1][l[i]] - 1 <= r[i]) {
                l[i] = jump[j & 1][l[i]];
                ans[i] += 1 << j;
            }
        }
    }
    for (int i = 1; i <= q; ++i) {
        cout << ans[i] << '\n';
    }
	return 0;
}

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

sumzero.cpp: In function 'int main()':
sumzero.cpp:35:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   35 |         if (last[sf] > 0) to[i] = min(to[i], last[sf]); last[sf] = i;
      |         ^~
sumzero.cpp:35:57: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   35 |         if (last[sf] > 0) to[i] = min(to[i], last[sf]); last[sf] = i;
      |                                                         ^~~~
sumzero.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sumzero.cpp:21:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...