QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591968#7181. Graph CutssitablechairRE 4ms7748kbC++234.1kb2024-09-26 19:33:532024-09-26 19:33:54

Judging History

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

  • [2024-09-26 19:33:54]
  • 评测
  • 测评结果:RE
  • 用时:4ms
  • 内存:7748kb
  • [2024-09-26 19:33:53]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long
#define ldb long double
#define endl '\n'
#define For(i,l,r) for(int i=l;i<=r;i++)
#define ForD(i,r,l) for(int i=r;i>=l;i--)
#define REP(i,l,r) For(i,l,r-1)
#define PER(i,r,l) ForD(i,r-1,l)
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define All(x,n) x+1,x+1+n
#define Alll(x,n) x,x+n
#define sz(x) (signed)x.size()
#define unq(x) x.resize(unique(all(x))-x.begin())
#define mpa make_pair

#ifdef NCGM
#include"debug.h"
#else 
#define debug(...) "fr";
#endif

using namespace std;

const int SQRT=320,N=1e5+3;
int n,m,q,sm[2][400][400],sum[2][400];
int small[400],smSum=0;
int id[N],id1[N],deg[N],cnt=0;
int idx[400][400];
pair<int,int> ed[N];
bool del[N],state[N];
vector<int> g[N];

int find_edge(bool st,int v) {
    if (sum[st][v]==0) return -1;
    For(i,0,(m-1)/SQRT) 
        if (sm[st][v][i]>0) 
            For(j,i*SQRT+1,min((i+1)*SQRT,m)) 
                if (!del[j] && state[ed[j].ff]!=state[ed[j].ss]) return j;
    // assert(false);
    return -1;
}
int find_edge_small() {
    if (smSum==0) return -1;
    For(i,0,(m-1)/SQRT) 
        if (small[i]>0) 
            For(j,i*SQRT+1,min((i+1)*SQRT,m)) 
                if (!del[j] && state[ed[j].ff]!=state[ed[j].ss]) return j;
    // assert(false);
    return -1;
}
void dele(int rem) {
    del[rem]=1;
    if (deg[ed[rem].ff]>SQRT) {
        sm[!state[ed[rem].ss]][id[ed[rem].ff]][(rem-1)/SQRT]--;
        sum[!state[ed[rem].ss]][id[ed[rem].ff]]--;
    }
    if (deg[ed[rem].ss]>SQRT) {
        sm[!state[ed[rem].ff]][id[ed[rem].ss]][(rem-1)/SQRT]--;
        sum[!state[ed[rem].ff]][id[ed[rem].ss]]--;
    } else if (deg[ed[rem].ff]<=SQRT) {
        smSum--;
        small[(rem-1)/SQRT]--;
    }
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m;
    For(i,1,m) {
        cin >> ed[i].ff >> ed[i].ss;
        deg[ed[i].ff]++;
        deg[ed[i].ss]++;
        g[ed[i].ff].pb(i);
        g[ed[i].ss].pb(i);
    } 
    cin >> q;
    For(i,1,n) 
        if (deg[i]>SQRT) {
            id[i]=++cnt;
            id1[cnt]=i;
            For(j,1,m) 
                if (ed[j].ff==i ||ed[j].ss==i) sm[1][cnt][(j-1)/SQRT]++,sum[1][cnt]++;
        }
    if (cnt>=400) return !(cout << -69 << endl);
    For(i,1,m) 
        if (deg[ed[i].ff]>SQRT && deg[ed[i].ss]>SQRT) 
            idx[id[ed[i].ff]][id[ed[i].ss]]=idx[id[ed[i].ss]][id[ed[i].ff]]=i;
    For(qr,1,q) {
        char c;
        int u;
        cin >> c;
        if (c!='?') {
            cin >> u;
            bool ki=(c=='+');
            state[u]=ki;
            if (deg[u]>SQRT) {
                For(i,1,cnt) {
                    if (i==id[u] || idx[id[u]][i]==0) continue;
                    if (del[idx[id[u]][i]]) continue;
                    sum[!state[u]][i]++;
                    sum[state[u]][i]--;
                    sm[!state[u]][i][(idx[id[u]][i]-1)/SQRT]++;
                    sm[state[u]][i][(idx[id[u]][i]-1)/SQRT]--;
                }
            } else {
                for(auto ski: g[u]) {
                    if (del[ski]) continue;
                    int v=(ed[ski].ff==u?ed[ski].ss:ed[ski].ff);
                    if (deg[v]>SQRT) {
                        sum[!state[u]][id[v]]++;
                        sum[state[u]][id[v]]--;
                        sm[!state[u]][id[v]][(ski-1)/SQRT]++;
                        sm[state[u]][id[v]][(ski-1)/SQRT]--;
                    } else {
                        int emra=(state[u]==state[v]?-1:1);
                        smSum+=emra;
                        small[(ski-1)/SQRT]+=emra;
                    } 
                }
            }
        } else {
            int rem=find_edge_small();
            if (rem==-1) {
                For(i,1,cnt) {
                    rem=find_edge(state[id1[i]],i);
                    if (rem!=-1) break;
                }
            }   
            if(rem!=-1) {
                cout << rem << endl;
                dele(rem);
            } else cout << 0 << endl;
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7728kb

input:

4 5
1 2
1 3
1 4
2 3
2 4
10
+ 1
+ 2
?
?
?
?
?
- 2
?
?

output:

2
3
4
5
0
1
0

result:

ok q=10

Test #2:

score: 0
Accepted
time: 1ms
memory: 3700kb

input:

0 0
0

output:


result:

ok q=0

Test #3:

score: 0
Accepted
time: 1ms
memory: 3572kb

input:

0 0
1
?

output:

0

result:

ok q=1

Test #4:

score: 0
Accepted
time: 4ms
memory: 7748kb

input:

1000 2000
1 50
1 88
331 1
1 352
1 497
2 32
2 282
550 2
989 2
334 3
3 665
4 38
4 69
4 343
4 451
589 4
917 4
89 5
5 162
675 5
681 6
7 22
127 7
7 592
7 672
787 7
8 310
107 9
9 137
184 9
9 244
378 9
446 9
9 658
883 9
65 10
75 10
414 10
10 468
686 10
245 11
269 11
11 386
403 11
493 11
394 12
493 12
565 1...

output:

1
4
5
8
9
10
12
14
16
18
19
25
27
29
33
38
39
40
42
47
48
49
50
56
58
59
62
63
67
69
70
71
73
75
79
81
82
83
84
87
89
91
94
97
101
103
104
106
107
108
109
110
113
114
115
118
120
121
122
125
126
129
130
131
132
133
134
135
137
145
147
148
34
149
152
153
154
155
156
157
159
160
163
167
171
105
173
17...

result:

ok q=100000

Test #5:

score: -100
Runtime Error

input:

447 99681
2 1
1 3
4 1
1 5
1 6
1 7
1 8
9 1
10 1
1 11
1 12
1 13
1 14
1 15
1 16
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
1 26
27 1
28 1
1 29
30 1
31 1
1 32
33 1
1 34
1 35
36 1
37 1
38 1
39 1
40 1
1 41
1 42
43 1
44 1
45 1
46 1
1 47
48 1
49 1
1 50
1 51
1 52
53 1
54 1
55 1
1 56
57 1
1 58
59 1
60 1
1 6...

output:


result: