QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#791957#9810. Obliviate, Then ReincarnateClclclclWA 6ms23180kbC++202.9kb2024-11-28 22:27:292024-11-28 22:27:31

Judging History

This is the latest submission verdict.

  • [2024-11-28 22:27:31]
  • Judged
  • Verdict: WA
  • Time: 6ms
  • Memory: 23180kb
  • [2024-11-28 22:27:29]
  • Submitted

answer

# include <bits/stdc++.h>

using namespace std;
using ll = long long;

# define int long long
# define endl '\n'
# define cy cout << "Yes" << endl
# define cn cout << "No" << endl
# define pb push_back
# define fi first
# define se second
# define in insert
# define all(a) a.begin(), a.end()
# define rep(i,a,n) for (int i = a;i <= n;i ++)
# define per(i,a,n) for (int i = n;i >= a;i --)

typedef pair<int,int> PII;
typedef double db;

const int N = 5e5 + 10;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int INF = 1e17;

priority_queue<ll,vector<ll>, greater<ll> > mi;
priority_queue<ll> ma;

vector <int> g[N],ng[N];
vector <int> pos[N];
int n,m,k;
int dfn[N],low[N],tim;
int stk[N],top;
bool in_stk[N];
int dout[N],din[N];
int id[N],cnt,Size[N];
int dp[N],w[N],nw[N];
int f[N];

void tarjan(int u){
	dfn[u] = low[u] = ++ tim;
	stk[ ++ top] = u,in_stk[u] = true;

	for (auto l : g[u]){
		if (!dfn[l]){
			tarjan(l);
			low[u] = min(low[u],low[l]);
		}
		else if (in_stk[l]) low[u] = min(low[u],dfn[l]);
	}

	if (dfn[u] == low[u]){
		++ cnt;
		int y;
		do{
			y = stk[top --];
			in_stk[y] = false;
			id[y] = cnt;
			Size[cnt] ++;
			pos[cnt].pb(y);
		}while(y != u);
	}
}

void solve() {
    vector <vector <PII>> g2(N + 1);

    cin >> n >> m >> k;
    for(int i = 1;i <= m;i ++ ){
    	int l,r;
    	cin >> l >> r;
    	int w = r;
    	l = ((l + n) % n);
    	r = ((l + r) + n) % n;
    	l ++;
    	r ++;
    	g2[l].pb({r,w});
    	g[l].pb(r);
    }

    for(int i = 1;i <= n;i ++ ){
    	if(!dfn[i]) tarjan(i);
    }

    for(int i = 1;i <= cnt;i ++ ){
    	int a = id[i];
    	for(auto l : g[i]){
    		int b = id[l];
    		if(a != b){
    			ng[b].pb(a);
    			din[a] ++;
    		}
    	}
    }

    vector <int> ok(n + 1,0);
    vector <bool> st(n + 1,0);
    vector <int> dist(n + 1,0);
    auto dfs = [&] (auto dfs,int u,int p) -> void{
    	st[u] = 1;
    	for(auto [l,w] : g2[u]){
    		if(id[l] != p) continue;
    		if(st[l]){
    			if(dist[l] + w != dist[u]){
    				ok[p] = 1;
    			}
    			return;
    		}
    		dist[l] = dist[u] + w;
    		dfs(dfs,l,p);
    	}
    };

    for(int i = 1;i <= cnt;i ++ ){
    	dfs(dfs,pos[i][0],i);
    }

    auto topsort = [&] () -> void{
    	queue <int> q;
    	for(int i = 1;i <= cnt;i ++ ){
    		if(!din[i]) q.push(i);
    	}

    	while(q.size()){
    		auto u = q.front();
    		q.pop();

    		for(auto l : ng[u]){
    			(ok[l] |= ok[u]);
    			if(-- din[l] == 0) q.push(l);
    		}
    	}
    };
    topsort();

    while(k -- ){
    	int l;
    	cin >> l;
    	l = (l + n) % n + 1;
    	l = id[l];
    	if(ok[l]) cy;
    	else cn; 
    }
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int _ = 1;
    //cin >> _ ;

    while( _ -- )
    {

        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 23180kb

input:

3 2 3
1 1
-1 3
1
2
3

output:

Yes
Yes
No

result:

ok 3 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 23144kb

input:

3 2 3
1 1
-1 0
1
2
3

output:

No
No
No

result:

ok 3 tokens

Test #3:

score: 0
Accepted
time: 6ms
memory: 21036kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

score: -100
Wrong Answer
time: 5ms
memory: 21088kb

input:

3 2 3
0 1000000000
1 -1000000000
-1000000000
0
-1000000000

output:

No
Yes
No

result:

wrong answer 2nd words differ - expected: 'No', found: 'Yes'