제출 #726144

#제출 시각아이디문제언어결과실행 시간메모리
726144anusha777Sum Zero (RMI20_sumzero)C++14
0 / 100
11 ms1364 KiB
#include <bits/stdc++.h> #define fast ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL) #define sz(x) (int)((x).size()) #define pb push_back #define vi vector<int> #define vb vector<bool> #define vvb vector<vb> #define pi pair<int,int> #define vpi vector<pi> #define vvi vector<vi> #define vc vector<char> #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pbb() pop_back() //#define f first #define s second #define ll long long #define int long long #define ull unsigned long long #define line cout<<"_____________________________"<<endl; #define forr(i, a, b) for(int i=a; i<b; i++) const int N=50000+1, mod=1e9+7, inf=1e18+1; using namespace std; //vi dx= { 0, 1, 0 , -1} , dy= {-1,0, 1, 0}; void setIO(string filename) { freopen((filename + ".in").c_str(), "r", stdin); freopen((filename + ".out").c_str(), "w", stdout); } int a[400003]={0}; int jump[400003][20]={0}; int walk(int u, int h) { for(int i=0, x=1; i<20; i++, x*=2ll) if((h&x)==x) u= jump[u][i]; return u; } void task() { int n; cin>>n; forr(i, 0, n) cin>>a[i]; // if no jump: then n+1 th element for(int i=1; i<20; i++) jump[n+1][i]=jump[n][i]=n+1; map<int, int> lastp; int p=0; lastp[0]=n; for(int i=n-1; i>=0; i--) { p+=a[i]; int r= lastp[p]; jump[i][0]= jump[i+1][0]; if(r!=0) jump[i][0]=r; lastp[p]=i; forr(j, 1, 20) jump[i][j]= jump[jump[i][j-1]][j-1]; } int q; cin>>q; while(q--) { int L, R; cin >> L >> R; L--; int l=0, r=n+1; while(r>l+1) { int m= (l+r)/2, x= walk(L, m); if(x<=R) l=m; else r=m; } cout<<l<<endl; } } signed main() { fast; int t; t=1; //cin>>t; while(t--) task(); }

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

sumzero.cpp: In function 'void setIO(std::string)':
sumzero.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sumzero.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...