이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ldb long double
#define db double
#define fin(x) freopen(x,"r",stdin)
#define fout(x) freopen(x,"w",stdout)
#define fo(i,l,r) for(int i=(l);i<=(r);i++)
#define foi(i,l,r) for(int i=(l);i>=(r);i--)
#define el cout<<'\n';
#define cel cerr<<'\n';
#define all(x) x.begin(),x.end()
#define ii pair<int,int>
#define iii pair<int,ii>
#define gb(x,i) (((x)>>(i))&1)
#define mask(i) (1LL<<(i))
#define TIME (1.0 * clock()/CLOCKS_PER_SEC)
using namespace std;
const int N=4e5+5;
const int bl=350;
const ll base=1e9+7;
const ll inf=1e9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll l,ll r)
{
return l+(1ll*rng()*rng()%(r-l+1)+(r-l+1))%(r-l+1);
}
template<class X,class Y>bool maximize(X &a,Y b)
{
if(a<b) return a=b,true;
return false;
}
template<class X,class Y>bool minimize(X &a, Y b)
{
if(a>b) return a=b,true;
return false;
}
void add(auto &a,auto b)
{
a+=b;
if(a>=base) a-=base;
if(a<0) a+=base;
}
int n,x,nxt[5][N],q;
ll sum[N];
int pw[5];
unordered_map<ll,int>cc;
void solve()
{
int l,r,ans=0;
cin>>l>>r,l--;
foi(i,4,0) while(nxt[i][l]<=r) ans+=pw[i],l=nxt[i][l];
cout<<ans,el
}
int main()
{
#define task "o"
if(fopen(task".inp","r"))
{
fin(task".inp");
fout(task".out");
}
srand(time(NULL));
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n;
fo(i,1,n) cin>>x,sum[i]=sum[i-1]+x;
nxt[0][n+1]=n+1;
foi(i,n,0)
{
if(cc.count(sum[i])) nxt[0][i]=min(nxt[0][i+1],cc[sum[i]]);
else nxt[0][i]=nxt[0][i+1];
cc[sum[i]]=i;
}
pw[0]=1;
fo(i,1,15) pw[i]=pw[i-1]*15;
fo(x,1,4) fo(i,0,n)
{
int pos=nxt[x-1][i];
fo(c,1,14) if(pos<=n) pos=nxt[x-1][pos];
nxt[x][i]=pos;
}
cin>>q;
while(q--) solve();
cerr<<"Time elapsed: "<<TIME<<" s.\n";
}
컴파일 시 표준 에러 (stderr) 메시지
sumzero.cpp:41:10: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
41 | void add(auto &a,auto b)
| ^~~~
sumzero.cpp:41:18: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
41 | void add(auto &a,auto b)
| ^~~~
sumzero.cpp: In function 'int main()':
sumzero.cpp:9:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | #define fin(x) freopen(x,"r",stdin)
| ~~~~~~~^~~~~~~~~~~~~
sumzero.cpp:63:9: note: in expansion of macro 'fin'
63 | fin(task".inp");
| ^~~
sumzero.cpp:10:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | #define fout(x) freopen(x,"w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~
sumzero.cpp:64:9: note: in expansion of macro 'fout'
64 | fout(task".out");
| ^~~~
sumzero.cpp:78:28: warning: iteration 5 invokes undefined behavior [-Waggressive-loop-optimizations]
78 | fo(i,1,15) pw[i]=pw[i-1]*15;
| ~~~~~~^
sumzero.cpp:11:34: note: within this loop
11 | #define fo(i,l,r) for(int i=(l);i<=(r);i++)
| ^
sumzero.cpp:78:5: note: in expansion of macro 'fo'
78 | fo(i,1,15) pw[i]=pw[i-1]*15;
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |