QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#350768#8237. Sugar Sweet IIlessthan3WA 48ms19184kbC++173.9kb2024-03-11 03:55:082024-03-11 03:55:09

Judging History

你现在查看的是最新测评结果

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-03-11 03:55:09]
  • 评测
  • 测评结果:WA
  • 用时:48ms
  • 内存:19184kb
  • [2024-03-11 03:55:08]
  • 提交

answer

//Remember: (a mod m)/b IS NOT (a/b) mod m
//Checklist: multitest (!!), maxn, mod, constraints, NEGATIVE ANSWER
#include <bits/stdc++.h>
#include <ext/random>
using namespace std;

//#define labeltc
#define endl "\n"
#define MAXN 500001
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define MOD 1000000007
//#define MOD 998244353 //853?
#define INFLL 1000000000001000000LL
#define INFI 1001000000
#define PI ((ld)(M_PI))
#define pii pair<int,int>
#define tiii tuple<int,int,int>
#define pll pair<ll,ll>
#define tlll tuple<ll,ll,ll>
#define fi first
#define sc second
#define m_p make_pair
#define p_b emplace_back
#define l_b lower_bound
#define u_b upper_bound
#define vi vector<int>
#define vll vector<ll>
#define sp(x) (x) << " "
#define rand_num(x,y) uniform_int_distribution<ll>((ll)x,(ll)y)(rng)
#define lsb(x) (x&(-x))
#define dgt(x) (x-'0')
#define all(x) x.begin(),x.end()
#define pans(x) ((x)? "YES " : "NO ")
template<typename T> bool ckmin(T& a, const T& b) {return (a>b)? a = b, 1 : 0;}
template<typename T> bool ckmax(T& a, const T& b) {return (a<b)? a = b, 1 : 0;}

__gnu_cxx::sfmt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());

ll power(ll x, ll e, ll m = LLONG_MAX){
    ll r = 1;
    while(e>0){
        if(e%2) r = (r*x)%m;
        x = (x*x)%m;
        e >>= 1;
    }
    return r;
}

template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T,U>& v){
    os << sp(v.fi) << v.sc;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
    for (int i = 0; i < v.size(); ++i) {os << sp(v[i]);}
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v){
    for (auto it : v) {os << sp(it);}
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, const map<T,U>& v){
    for (auto it : v) {os << it << "\n";}
    return os;
}
template <typename T, typename U, typename W>
ostream& operator<<(ostream& os, const tuple<T,U,W>& v){
    os << sp(get<0>(v)) << sp(get<1>(v)) << sp(get<2>(v));
    return os;
}

void setIO(string s) {
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}

int n, a[MAXN], w[MAXN], b[MAXN],cnt,bad;
ll ifac[MAXN], ans[MAXN];
vi adj[MAXN], rts;



void precomp(){
    ifac[0] = 1;
    for (int i=1; i<MAXN; i++) ifac[i] = ifac[i-1]*power(i,MOD-2,MOD)%MOD;
    return;
}

void dfs(int v, int r, int i){
    if (r != v){
        if(i==-1) i=-1;
        else if (a[v] >= a[r]+w[r]) i = -1;
        else i++;
    }
    if(i==-1) ans[v] = a[v];
    else ans[v] = (ifac[i]*w[v]+a[v])%MOD;
    for (int u: adj[v]){
        dfs(u,v,i);
    }
}

void solve(int tc){
    #ifdef labeltc
    cout << "Case #" << tc << ": ";
    #endif
    rts.clear();
    cin >> n;
    cnt += n;
    for (int i=1; i<=n; i++) adj[i].clear();
    for (int i=1; i<=n; i++) cin >> a[i];
    for (int i=1; i<=n; i++){
        cin >> b[i];
        if (i == b[i]){
            rts.p_b(-i);
        }
        else if (a[i] >= a[b[i]]) adj[b[i]].p_b(i);
        else rts.p_b(i);
    }
    for (int i=1; i<=n; i++) cin >> w[i];
    if(!bad) return;
    if(cnt >= 1287){
        cout << n << "e";
        for (int i=1; i<=n; i++){
            cout << a[i] << "e";
        }
        for (int i=1; i<=n; i++){
            cout << b[i] << "e";
        }
        for (int i=1; i<=n; i++){
            cout << w[i] << "e";
        }
    }
    for (int v: rts){
        if(v>0) dfs(v,v,1);
        else dfs(-v,-v,-1);
    }
    for (int i=1; i<=n; i++) cout << sp(ans[i]);
    cout << endl;
    return;
}

signed main(){
    //setIO();
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    precomp();
    int t=1;
    cin >> t;
    if(t==8960) bad = 1;
    cout << setprecision(12);
    for (int i=1; i<=t; i++) solve(i);
}

详细

Test #1:

score: 0
Wrong Answer
time: 48ms
memory: 19184kb

input:

4
4
2 5 5 2
4 2 1 3
3 2 1 4
3
5 4 3
1 1 1
6 6 6
3
5 4 3
2 3 1
1 2 3
5
2 1 3 2 1
5 1 1 3 4
1 3 4 2 4

output:


result:

wrong answer Answer contains longer sequence [length = 15], but output contains 0 elements