結果
| 問題 |
No.590 Replacement
|
| コンテスト | |
| ユーザー |
Lepton_s
|
| 提出日時 | 2017-11-04 00:53:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,462 bytes |
| コンパイル時間 | 894 ms |
| コンパイル使用メモリ | 95,608 KB |
| 実行使用メモリ | 18,688 KB |
| 最終ジャッジ日時 | 2024-11-23 15:39:57 |
| 合計ジャッジ時間 | 89,274 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 WA * 7 RE * 9 TLE * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:61:17: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘ll*’ {aka ‘long long int*’} [-Wformat=]
61 | scanf("%d", &n);
| ~^ ~~
| | |
| | ll* {aka long long int*}
| int*
| %lld
main.cpp:61:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
61 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:63:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
63 | scanf("%lld", a[i]+j);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
// kinen submit
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 100100
ll n;
ll a[2][N], c[2][N], p[2][N], pr[2][N], used[N], ix[N], lp[N], dd[N], rr[N];
map<PP, vector<ll>> s;
void extgcd(ll x, ll y, ll &a, ll &b, ll &g){
if(y == 0){
a = 1;
b = 0;
g = x;
} else {
extgcd(y, x%y, a, b, g);
swap(a, b);
b -= a*x/y;
}
}
int main(){
scanf("%d", &n);
rep(i, 2) rep(j, n){
scanf("%lld", a[i]+j);
a[i][j]--;
}
mset(p, -1);
rep(i, 2) rep(j, n){
if(p[i][j] != -1) continue;
ll k = a[i][j];
p[i][j] = 1;
while(k != j){
c[i][k] = p[i][j]++;
pr[i][k] = j;
k = a[i][k];
}
pr[i][j] = j;
}
ll res = 0;
rep(j, n){
ll b[2], d;
extgcd(p[0][j], p[1][j], b[0], b[1], d);
ll r[2], q[2];
rep(i, 2) r[i] = c[i][j]%d;
if(r[1]<r[0]) r[1] += d;
rep(i, 2) q[i] = c[i][j]/d;
ll qq = q[1]-q[0];
b[0] *= qq; b[0] %= p[1][j]/d; if(b[0]<0) b[0] += p[1][j]/d;
b[1] * -qq; b[1] %= p[0][j]/d; if(b[1]<0) b[1] += p[0][j]/d;
ix[j] = b[0]*p[0][j]*d+r[0];
lp[j] = p[0][j]/d*p[1][j]/d;
dd[j] = d;
rr[j] = r[1]-r[0];
s[PP(P(pr[0][j], pr[1][j]), r[j])].push_back(j);
}
for(auto &&x: s){
auto &&v = x.snd;
int m = v.size();
vector<ll> vv(m+1);
rep(i, m) vv[i] = ix[v[i]];
v[m] = vv[0]+lp[v[0]];
rep(i, m){
ll y = vv[i+1]-vv[i]-1;
res += y*(y+1)/2;
res %= mod;
}
}
cout<<res<<endl;
return 0;
}
Lepton_s