QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#792064#9810. Obliviate, Then ReincarnateClclclclWA 223ms49560kbC++203.1kb2024-11-28 23:18:552024-11-28 23:18:55

Judging History

This is the latest submission verdict.

  • [2024-11-28 23:18:55]
  • Judged
  • Verdict: WA
  • Time: 223ms
  • Memory: 49560kb
  • [2024-11-28 23:18:55]
  • 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 din[N];
int id[N],cnt,Size[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() {
    cin >> n >> m >> k;
    vector <vector <PII>> g2(n + 1);
    for(int i = 1;i <= m;i ++ ){
    	int l,r;
    	cin >> l >> r;

    	int l1 = ((l % n + n) % n);
    	int r1 = ((l % n + r) % n + n) % n;
    	l1 ++;
    	r1 ++;
    	//cout << l1 << r1 << endl;
    	g2[l1].pb({r1,r});
    	g[l1].pb(r1);
    }

    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{
    	if(ok[u]) return;
    	st[u] = 1;
    	for(auto [l,w] : g2[u]){
    		if(id[l] != p) continue;
    		if(st[l]){
    			if(dist[u] + w != dist[l]){
    				//cout << dist[l] + w << ' ' << dist[u] << endl;
    				//cout << l << ' ' << u  << endl;
    				ok[p] = 1;
    				return;
    			}
    			continue;
    		}
    		dist[l] = dist[u] + w;

    		dfs(dfs,l,p);
    	}
    };

    for(int i = 1;i <= cnt;i ++ ){
    	//cout << pos[i][0] << endl;
    	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) % n + 1;
    	//cout << l;
    	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: 11716kb

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: 11880kb

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: 3ms
memory: 9988kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

score: 0
Accepted
time: 3ms
memory: 9784kb

input:

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

output:

No
No
No

result:

ok 3 tokens

Test #5:

score: 0
Accepted
time: 195ms
memory: 41964kb

input:

50134 500000 500000
-154428638 -283522863
-186373509 -327130969
154999046 46750274
-933523447 349415487
-437683609 140099255
864996699 -262318199
811293034 -264299324
120273173 52410685
874944410 -52048424
445049930 -803690605
-138111276 -104634331
720288580 126597671
471164416 -348777147
-356502322...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 500000 tokens

Test #6:

score: -100
Wrong Answer
time: 223ms
memory: 49560kb

input:

100848 500000 500000
720352587 361776806
231853504 -933882325
960971230 -83519300
-152772415 -631132247
842871215 -666621297
857194330 -754943024
-698506963 -705416545
-3551931 -927937446
628710320 -942247987
674921043 847145884
-325629529 475694308
-339363446 686789318
236702996 654762989
420412365...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Y...

result:

wrong answer 80th words differ - expected: 'Yes', found: 'No'