제출 #978997

#제출 시각아이디문제언어결과실행 시간메모리
978997NintsiChkhaidzeSum Zero (RMI20_sumzero)C++17
61 / 100
665 ms29272 KiB
#include <bits/stdc++.h>
#define ll long long
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
using namespace std;
 
const int N = 4e5 + 3;

int last[N];
int l[N],r[N],p[N];
int to[N],cur[N];

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
 
	int n,i,j,k;
	cin>>n;
	
	vector <int> vec;
	map <int,int> mp;
	vec.pb(0);
	for(i=1;i<=n;i++){
		cin>>p[i];
	}
	
	for (i = n; i >= 1; i--){
		p[i] += p[i + 1];
		vec.pb(p[i]);
	}
 
	sort(vec.begin(),vec.end());
	int val=0;
	for (i=0;i<vec.size();i++){
		if (!i || vec[i] != vec[i - 1]) {
			++val;
			mp[vec[i]] = val;
		}
	}
 
	for (i = 1; i <= n+1; i++)
		p[i] = mp[p[i]],last[p[i]] = 1e9;
 
	last[mp[0]] = n + 1;
	to[n+1] = 1e9;
	for (i = n; i >= 1; i--){
		to[i] = min(to[i + 1],last[p[i]]);
		last[p[i]] = i;
	}
	
	int q;
	cin>>q;
	
	for (i = 1; i <= q; i++){
		cin >> l[i] >> r[i];
		p[i] = 0;
	}
	
	for (i = 18; i >= 0; i--){
		for (j = 1; j <= n+1; j++)
			cur[j] = to[j];

		for (j = 1; j <= i; j++){
			for (k = 1; k <= n; k++){
				if (cur[k] <= n+1) cur[k] = cur[cur[k]];
			}
		}

		for (j = 1; j <= q; j++){
			if (cur[l[j]] <= r[j] + 1){
				l[j] = cur[l[j]];
				p[j] += (1<<i);
			}
		}
	}
 
	for (i=1;i<=q;i++)
		cout<<p[i]<<endl;
}

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

sumzero.cpp: In function 'int main()':
sumzero.cpp:35:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for (i=0;i<vec.size();i++){
      |           ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...