제출 #1319921

#제출 시각아이디문제언어결과실행 시간메모리
1319921sonarchtSum Zero (RMI20_sumzero)C++20
61 / 100
542 ms50016 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(v) begin(v), end(v)
#define pll pair<ll, ll>
#define fi first
#define se second
#define vll vector<ll>
#define mll map<ll, ll>
mt19937_64 rng(chrono::high_resolution_clock().now().time_since_epoch().count());
const ll N = 4e5 + 6, inf = 1e18 + 7, mod = 1e9 + 7;
ll n, m, k, q, ans, a[N], pf[N];
int li[N][20];
mll mp;

void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i];
	//for (int i = 1; i <= n; ++i) cout << a[i] << " "; cout << endl;
	for (int i = 1; i <= n; ++i) pf[i] = pf[i-1] + a[i];
	for (int i = 1; i <= n+2; ++i) li[i][0] = n+2;
	for (int i = n; i >= 1; --i) {
		mp[pf[i]] = i+1;
		if (mp.count(pf[i-1])) li[i][0] = mp[pf[i-1]];
		li[i][0] = min(li[i][0], li[i+1][0]);
	}
	//for (int i = 1; i <= n; ++i) cout << li[i][0] << " "; cout << endl;
	for (int j = 1; j <= 19; ++j) {
		for (int i = 1; i <= n; ++i) {
			li[i][j] = li[li[i][j-1]][j-1];
		}
	}
	//cout << li[1][2] << endl;
	cin >> q;
	while (q--) {
		ll l, r;
		cin >> l >> r;
		ll u = l, ans = 0;
		for (int j = 19; j >= 0; --j) {
			if (li[u][j] && li[u][j] <= r+1) {
				ans += (1 << j);
				u = li[u][j];
				//cout << j << endl;
			}
		}
		cout << ans << endl;
	}
	return;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	if (fopen(".INP", "r")) {
		freopen(".INP", "r", stdin);
		freopen(".OUT", "w", stdout);
	}
	ll tc = 1;
//	cin >> tc;
	while (tc--) {
		solve();
	}
	return 0;
}

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

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