Submission #203084

#TimeUsernameProblemLanguageResultExecution timeMemory
203084MercenaryBridges (APIO19_bridges)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #define pb push_back #define mp make_pair #define taskname "A" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; const int maxn = 2e5 + 5; const int mod = 1e9 + 7; struct Dsurollback{ pair<int*,int> data[(int)2e6]; int lab[maxn] , sz; int FindLab(int u){ return lab[u] < 0 ? u : FindLab(lab[u]); } void Change(int & u , int v){ data[sz++] = mp(&u,u); u = v; } void rollback(int sz1){ while(sz > sz1){ (*data[sz-1].first) = data[sz-1].second; --sz; } } int cnt = 0; int cnt1 = 0; void Merge(int u , int v){ u = FindLab(u);v = FindLab(v); if(u == v)return; if(lab[u] > lab[v])swap(u,v); Change(lab[u],lab[u]+lab[v]); Change(lab[v],u); } int cur(){return sz;}; void reset(int n){ fill_n(lab,n+2,-1); sz = 0; } }Dsu; int n , m , q; int u[maxn] , v[maxn] , d[maxn]; int out[maxn] , fakeid[maxn]; int type[maxn]; int res[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } cin >> n >> m; for(int i = 1 ; i <= m ; ++i){ cin >> u[i] >> v[i] >> d[i]; fakeid[i] = i; } cin >> q; for(int i = m + 1 ; i <= q + m ; ++i){ cin >> type[i]; if(type[i] == 1){ int x;cin >> x; u[i] = u[x];v[i] = v[x];cin >> d[i]; out[fakeid[x]] = i; fakeid[x] = i; }else{ cin >> u[i] >> d[i]; } } for(int i = 1 ; i <= m + q ; ++i)if(out[i] == 0)out[i] = q + m + 1; const int MAGIC = 300; vector<int> prepare; for(int i = 1 ; i <= m + q ; ++i)if(type[i] != 2)prepare.pb(i); sort(prepare.begin(),prepare.end() , [&](const int x , const int y){return d[x] > d[y];}); for(int l = m + 1 ; l <= m + q ; l += MAGIC){ int r = min(m + q ,l+MAGIC-1); vector<int> qval; Dsu.reset(n); vector<int> sp , norm; for(int i = l ; i <= r ; ++i){ if(type[i] == 2 && i >= l)qval.pb(i); } for(auto & i : prepare){ if(i > r || out[i] < l)continue; if(i < l && out[i] > r)norm.pb(i); else sp.pb(i); } sort(qval.begin(),qval.end(),[&](const int x , const int y){return d[x] > d[y];}); int it = 0; for(auto & id : qval){ while(it < norm.size() && d[id] <= d[norm[it]]){ Dsu.Merge(u[norm[it]],v[norm[it]]); ++it; } int tmp = Dsu.cur(); for(auto & c : sp){ if(d[id] > d[c])break; if(d[id] <= d[c] && c < id && out[c] > id){ Dsu.Merge(u[c],v[c]); } } res[id] = -Dsu.lab[Dsu.FindLab(u[id])]; Dsu.rollback(tmp); } } for(int i = m + 1 ; i <= m + q ; ++i)if(type[i] == 2)cout << res[i] << '\n'; } #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #define pb push_back #define mp make_pair #define taskname "A" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; const int maxn = 2e5 + 5; const int mod = 1e9 + 7; struct Dsurollback{ pair<int*,int> data[(int)2e6]; int lab[maxn] , sz; int FindLab(int u){ return lab[u] < 0 ? u : FindLab(lab[u]); } void Change(int & u , int v){ data[sz++] = mp(&u,u); u = v; } void rollback(int sz1){ while(sz > sz1){ (*data[sz-1].first) = data[sz-1].second; --sz; } } int cnt = 0; int cnt1 = 0; void Merge(int u , int v){ u = FindLab(u);v = FindLab(v); if(u == v)return; if(lab[u] > lab[v])swap(u,v); Change(lab[u],lab[u]+lab[v]); Change(lab[v],u); } int cur(){return sz;}; void reset(int n){ fill_n(lab,n+2,-1); sz = 0; } }Dsu; int n , m , q; int u[maxn] , v[maxn] , d[maxn]; int out[maxn] , fakeid[maxn]; int type[maxn]; int res[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } cin >> n >> m; for(int i = 1 ; i <= m ; ++i){ cin >> u[i] >> v[i] >> d[i]; fakeid[i] = i; } cin >> q; for(int i = m + 1 ; i <= q + m ; ++i){ cin >> type[i]; if(type[i] == 1){ int x;cin >> x; u[i] = u[x];v[i] = v[x];cin >> d[i]; out[fakeid[x]] = i; fakeid[x] = i; }else{ cin >> u[i] >> d[i]; } } for(int i = 1 ; i <= m + q ; ++i)if(out[i] == 0)out[i] = q + m + 1; const int MAGIC = 300; vector<int> prepare; for(int i = 1 ; i <= m + q ; ++i)if(type[i] != 2)prepare.pb(i); sort(prepare.begin(),prepare.end() , [&](const int x , const int y){return d[x] > d[y];}); for(int l = m + 1 ; l <= m + q ; l += MAGIC){ int r = min(m + q ,l+MAGIC-1); vector<int> qval; Dsu.reset(n); vector<int> sp , norm; for(int i = l ; i <= r ; ++i){ if(type[i] == 2 && i >= l)qval.pb(i); } for(auto & i : prepare){ if(i > r || out[i] < l)continue; if(i < l && out[i] > r)norm.pb(i); else sp.pb(i); } sort(qval.begin(),qval.end(),[&](const int x , const int y){return d[x] > d[y];}); int it = 0; for(auto & id : qval){ while(it < norm.size() && d[id] <= d[norm[it]]){ Dsu.Merge(u[norm[it]],v[norm[it]]); ++it; } int tmp = Dsu.cur(); for(auto & c : sp){ if(d[id] > d[c])break; if(d[id] <= d[c] && c < id && out[c] > id){ Dsu.Merge(u[c],v[c]); } } res[id] = -Dsu.lab[Dsu.FindLab(u[id])]; Dsu.rollback(tmp); } } for(int i = m + 1 ; i <= m + q ; ++i)if(type[i] == 2)cout << res[i] << '\n'; }

Compilation message (stderr)

bridges.cpp: In function 'int main()':
bridges.cpp:104:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(it < norm.size() && d[id] <= d[norm[it]]){
                   ~~~^~~~~~~~~~~~~
bridges.cpp: At global scope:
bridges.cpp:138:11: error: redefinition of 'const int maxn'
 const int maxn = 2e5 + 5;
           ^~~~
bridges.cpp:17:11: note: 'const int maxn' previously defined here
 const int maxn = 2e5 + 5;
           ^~~~
bridges.cpp:139:11: error: redefinition of 'const int mod'
 const int mod = 1e9 + 7;
           ^~~
bridges.cpp:18:11: note: 'const int mod' previously defined here
 const int mod = 1e9 + 7;
           ^~~
bridges.cpp:141:8: error: redefinition of 'struct Dsurollback'
 struct Dsurollback{
        ^~~~~~~~~~~
bridges.cpp:20:8: note: previous definition of 'struct Dsurollback'
 struct Dsurollback{
        ^~~~~~~~~~~
bridges.cpp:171:2: error: conflicting declaration 'int Dsu'
 }Dsu;
  ^~~
bridges.cpp:50:2: note: previous declaration as 'Dsurollback Dsu'
 }Dsu;
  ^~~
bridges.cpp:173:5: error: redefinition of 'int n'
 int n , m , q;
     ^
bridges.cpp:52:5: note: 'int n' previously declared here
 int n , m , q;
     ^
bridges.cpp:173:9: error: redefinition of 'int m'
 int n , m , q;
         ^
bridges.cpp:52:9: note: 'int m' previously declared here
 int n , m , q;
         ^
bridges.cpp:173:13: error: redefinition of 'int q'
 int n , m , q;
             ^
bridges.cpp:52:13: note: 'int q' previously declared here
 int n , m , q;
             ^
bridges.cpp:174:11: error: redefinition of 'int u [200005]'
 int u[maxn] , v[maxn] , d[maxn];
           ^
bridges.cpp:53:5: note: 'int u [200005]' previously declared here
 int u[maxn] , v[maxn] , d[maxn];
     ^
bridges.cpp:174:21: error: redefinition of 'int v [200005]'
 int u[maxn] , v[maxn] , d[maxn];
                     ^
bridges.cpp:53:15: note: 'int v [200005]' previously declared here
 int u[maxn] , v[maxn] , d[maxn];
               ^
bridges.cpp:174:31: error: redefinition of 'int d [200005]'
 int u[maxn] , v[maxn] , d[maxn];
                               ^
bridges.cpp:53:25: note: 'int d [200005]' previously declared here
 int u[maxn] , v[maxn] , d[maxn];
                         ^
bridges.cpp:175:13: error: redefinition of 'int out [200005]'
 int out[maxn] , fakeid[maxn];
             ^
bridges.cpp:54:5: note: 'int out [200005]' previously declared here
 int out[maxn] , fakeid[maxn];
     ^~~
bridges.cpp:175:28: error: redefinition of 'int fakeid [200005]'
 int out[maxn] , fakeid[maxn];
                            ^
bridges.cpp:54:17: note: 'int fakeid [200005]' previously declared here
 int out[maxn] , fakeid[maxn];
                 ^~~~~~
bridges.cpp:176:14: error: redefinition of 'int type [200005]'
 int type[maxn];
              ^
bridges.cpp:55:5: note: 'int type [200005]' previously declared here
 int type[maxn];
     ^~~~
bridges.cpp:177:13: error: redefinition of 'int res [200005]'
 int res[maxn];
             ^
bridges.cpp:56:5: note: 'int res [200005]' previously declared here
 int res[maxn];
     ^~~
bridges.cpp: In function 'int main()':
bridges.cpp:179:5: error: redefinition of 'int main()'
 int main()
     ^~~~
bridges.cpp:58:5: note: 'int main()' previously defined here
 int main()
     ^~~~
bridges.cpp:225:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(it < norm.size() && d[id] <= d[norm[it]]){
                   ~~~^~~~~~~~~~~~~
bridges.cpp: In function 'int main()':
bridges.cpp:63:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:64:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp: In function 'int main()':
bridges.cpp:184:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.cpp:185:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~