QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#792004 | #9810. Obliviate, Then Reincarnate | Clclclcl | RE | 7ms | 35028kb | C++20 | 3.1kb | 2024-11-28 22:50:53 | 2024-11-28 22:50:54 |
Judging History
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 = 6e5 + 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 ++;
//cout << l << r << endl;
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{
if(st[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;
}
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 + 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: 4ms
memory: 34952kb
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: 4ms
memory: 35028kb
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: 32920kb
input:
1 1 1 0 1000000000 -1000000000
output:
Yes
result:
ok "Yes"
Test #4:
score: 0
Accepted
time: 7ms
memory: 32836kb
input:
3 2 3 0 1000000000 1 -1000000000 -1000000000 0 -1000000000
output:
No No No
result:
ok 3 tokens
Test #5:
score: -100
Runtime Error
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...