QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#611234#8237. Sugar Sweet IIba_creeperML 0ms0kbC++143.2kb2024-10-04 20:01:112024-10-04 20:01:11

Judging History

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

  • [2024-11-04 16:59:03]
  • hack成功,自动添加数据
  • (/hack/1109)
  • [2024-10-04 20:01:11]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2024-10-04 20:01:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define re read()
#define INF 9223372036854775800
#define fr(i, x, y) for (int i = x, _ = y; i <= _; ++i)
#define rp(i, x, y) for (int i = x, _ = y; i >= _; --i)
#define Timeok ((double)clock() / CLOCKS_PER_SEC < MAX_TIME)
const double MAX_TIME = 1.0 - 0.0032;

inline ll read()
{
    ll x = 0, f = 0;
    char ch = getchar();
    while (!isdigit(ch))
        f |= (ch == '-'), ch = getchar();
    while (isdigit(ch))
        x = (x << 1) + (x << 3) + (ch ^= 48), ch = getchar();
    return f ? -x : x;
}

void write(ll x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + 48);
}

inline void W(ll x, char ch)
{
    write(x);
    putchar(ch);
}

/*------------C-O-D-E------------*/

const int N = 1e6 + 32;
const ll mod = 1e9 + 7;

ll n, m, k;

ll ksm(ll a, ll b)
{
    a %= mod;
    ll ret = 1 % mod;
    while(b)
    {
        if(b & 1)
            ret = ret * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return ret % mod;
}

ll Frac(ll x, ll y)
{
    return x * ksm(y, mod - 2) % mod;
}

struct edge
{
    ll to, nxt, opt;
} t[N];

ll head[N], tot, a[N], b[N], w[N];
ll c[N], d[N];
bool vis[N];

void add(ll u, ll v, ll opt)
{
    t[++tot].nxt = head[u];
    t[tot].to = v;
    t[tot].opt = opt;
    head[u] = tot;
}

void dfs(ll x)
{
    
    for(int i = head[x]; i; i = t[i].nxt)
    {
        ll y = t[i].to;
        if(t[i].opt == 2) 
        {
            if(d[x] == 0)
            {
                c[y] = d[y] = 0;
            }
            else
            {
                c[y] = c[x] * Frac(1, d[x] + 1) % mod;
                d[y] = d[x] + 1;
            }
        }
        if(t[i].opt == 0) c[y] = 0, d[y] = 0;
        if(t[i].opt == 1) c[y] = 1, d[y] = 1;
        dfs(y);
    }
}

vector<ll> s;
int main()
{
    // cin.tie(0);
    // cout.tie(0);
    // ios::sync_with_stdio(false);
    ll T = re;
    while(T--)
    {
        n = re;
        fr(i, 1, n) a[i] = re;
        fr(i, 1, n) b[i] = re;
        fr(i, 1, n) w[i] = re;
        fr(i, 1, n)
        {
            if(i == b[i]) continue;
            int opt;
            if(a[i] < a[b[i]]) opt = 1;
            else if(a[i] >= a[b[i]] + w[b[i]]) opt = 0;
            else opt = 2;
            if(opt == 0 || opt == 1)
            {
                s.push_back(b[i]);
            }
            if(opt == 0) c[i] = d[i] = 0;
            if(opt == 1) c[i] = d[i] = 1;
            // cout<<b[i]<<' '<<i<<' '<<opt<<endl;
            add(b[i], i, opt);
        }

        fr(x, 1, n)
        {
            dfs(x);
        }
        // fr(i, 1, n) cout<<c[i]<<' ';
        fr(i, 1, n)
        {
            ll ans = 0;
            ans = (((a[i] + w[i]) % mod )* c[i] )% mod;
            ll lc = (1 - c[i] + mod) % mod;
            ans = (ans + (lc * a[i]) % mod) % mod;
            W(ans, ' ');
        }
        puts("");
        
        s.clear();
        fr(i, 1, n) a[i] = b[i] = w[i] = c[i] = 0;
        fr(i, 1, n) vis[i] = 0;
        tot = 0;
        fr(i, 1, n) head[i] = 0, t[i] = {0,0,0}, d[i] = 0;
    }

    return 0;
}   

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

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: