이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
#define pii pair<int,int>
#define ll long long
#define fs first
#define sc second
#define _all(T) T.begin(),T.end()
#define pll pair<ll,ll>
const int MX = 3e7+10;
const int mod = 1e9+7;
const int mxn = 1e5+10;
vector<pii> all;
int dp[mxn];
int ans[mxn];
pll arr[mxn];
int N;
int pos[mxn];
int head[mxn],nid[MX],tp[MX],idx[MX];
int ptr = 0;
void add_op(int a,int p,int id){
ptr++;
assert(ptr<MX);
nid[ptr] = head[a];
head[a] = ptr;
tp[ptr] = p;
idx[ptr] = id;
return;
}
inline int mad(int a,int b){
a += b;
return a>=mod?a-mod:a;
}
inline int mub(int a,int b){
a += mod-b;
return a>=mod?a-mod:a;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N;
for(int i = 1;i<=N;i++){
cin>>arr[i].fs>>arr[i].sc;
if(arr[i].fs)all.push_back(pii(arr[i].fs,i%arr[i].fs));
}
sort(_all(all));all.resize(unique(_all(all))-all.begin());
for(int i = 1;i<=N;i++){
if(!arr[i].fs)continue;
pos[i] = lower_bound(_all(all),pii(arr[i].fs,i%arr[i].fs))-all.begin();
ll rp = 1ll*arr[i].fs*arr[i].sc+i;
if(rp<=N)add_op(rp,pos[i],-i);
}
for(int i = 0;i<all.size();i++){
for(int j = all[i].sc;j<=N;j+=all[i].fs){
add_op(j,i,i);
}
}
if(!arr[1].fs||!arr[1].sc){
cout<<"1\n";
return 0;
}
ans[1] = 1;
dp[pos[1]] = 1;
for(int i = 2;i<=N;i++){
for(int eid = head[i];eid;eid = nid[eid]){
int p = tp[eid],id = idx[eid];
if(id<0){
id = -id;
dp[p] = mub(dp[p],ans[id]);
}
else{
ans[i] = mad(ans[i],dp[p]);
}
}
if(arr[i].fs)dp[pos[i]] = mad(dp[pos[i]],ans[i]);
}
/*
for(auto &i:all)cerr<<i.fs<<','<<i.sc<<' ';cerr<<endl;
for(int i = 1;i<=N;i++){
cerr<<i<<","<<ans[i]<<"::";
for(int eid = head[i];eid;eid = nid[eid])cerr<<tp[eid]<<','<<idx[eid]<<' ';cerr<<endl;
}
*/
int sum = 0;
for(int i = 1;i<=N;i++)sum = mad(sum,ans[i]);
cout<<sum<<'\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'int main()':
Main.cpp:61:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int i = 0;i<all.size();i++){
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |