Submission #1265062

#TimeUsernameProblemLanguageResultExecution timeMemory
1265062sasdeMaking Friends on Joitter is Fun (JOI20_joitter2)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;
bool M1;
#define PI 3.14159265358979323846
#define sz(a) (int)a.size()
#define all(x) x.begin(),x.end()
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii,ii>
#define se second
#define fi first
#define ffi fi.fi
#define sfi se.fi
#define sse se.se
#define fse fi.se
#define lt(i, c, d) for(int i = c; i <= d; ++i)
#define fl(i, c, d) for(int i = d; i >= c; --i)
#define pb push_back
#define emb emplace_back
#define emf emplace_front
#define em emplace
#define int long long
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<'\n'
#define look_time   cerr << "TIME : " << clock() * 0.001 << "s" <<'\n'
const int N=1e5+5,lg=30,mod=1e9+7;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int u,int v){
 return u+rd()%(v-u+1);
}
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,1,-1,1,-1};
int node,m,a[N],ans,cnt[N];
queue<ii>p;
map<int,int>in[N];
set<ii>s[N];
struct DSU
{
    int n;
    vector<int>r;
    DSU(){};
    DSU(int _n):n(_n),r(n+5,-1){};
    int acs(int u){
        return r[u]<0?u:r[u]=acs(r[u]);
    }
    void Erase(int u,int v){
        ans+=r[v];
        s[acs(u)].erase({v,u});
        in[v].erase(u);
        p.em(u,v);
        // cout <<u<<" "<<v<<'\n';
    }
    void join(int u,int v){

        if(cnt[u]>cnt[v])swap(u,v);
        while(sz(s[u])){
            ii j=*s[u].begin();
            Erase(j.se,j.fi);
        }
        while(sz(in[u])){
            Erase(in[u].begin()->fi,u);
        }
        ans+=r[u]*r[v]*2;
        ans+=sz(in[v])*-r[u];
            r[v]+=r[u];
            r[u]=v;
    }
}dsu;
void add(int u,int v){
    v=dsu.acs(v);
    u=dsu.acs(u);
    // cout <<u<<" "<<v<<'\n';
    if(dsu.acs(u)==v||in[v][u])return;
    // cout <<1<<'\n';
    // cout <<u<<" "<<v<<'\n';
    in[v][u]=1;
    ans+=-dsu.r[v];
    s[u].insert({v,u});
    ++cnt[u];
    ++cnt[v];
    auto it=s[v].lower_bound(make_pair(u,-1));
    if(it->fi==u)
        dsu.join(u,v);
}
bool M2;
void solve(){
    cin >> node >> m;
    dsu=DSU(node);
    for(int i=1;i<=m;++i){
        int u,v;
        cin >> u >> v;
        p.em(u,v);
        while(!p.empty()){
            u=p.front().fi;
            v=p.front().se;    
            // cout <<u<<" "<<v<<'\n';        
            p.pop();
            ad#include<bits/stdc++.h>
using namespace std;
bool M1;
#define PI 3.14159265358979323846
#define sz(a) (int)a.size()
#define all(x) x.begin(),x.end()
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii,ii>
#define se second
#define fi first
#define ffi fi.fi
#define sfi se.fi
#define sse se.se
#define fse fi.se
#define lt(i, c, d) for(int i = c; i <= d; ++i)
#define fl(i, c, d) for(int i = d; i >= c; --i)
#define pb push_back
#define emb emplace_back
#define emf emplace_front
#define em emplace
#define int long long
#define look_memory cerr<<abs(&M2-&M1)/1024.0/1024<<'\n'
#define look_time   cerr << "TIME : " << clock() * 0.001 << "s" <<'\n'
const int N=1e5+5,lg=30,mod=1e9+7;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int u,int v){
 return u+rd()%(v-u+1);
}
int dx[]={1,0,-1,0,1,1,-1,-1};
int dy[]={0,-1,0,1,1,-1,1,-1};
int node,m,a[N],ans,cnt[N];
queue<ii>p;
map<int,int>in[N];
set<ii>s[N];
struct DSU
{
    int n;
    vector<int>r;
    DSU(){};
    DSU(int _n):n(_n),r(n+5,-1){};
    int acs(int u){
        return r[u]<0?u:r[u]=acs(r[u]);
    }
    void Erase(int u,int v){
        ans+=r[v];
        s[acs(u)].erase({v,u});
        in[v].erase(u);
        p.em(u,v);
        // cout <<u<<" "<<v<<'\n';
    }
    void join(int u,int v){

        if(cnt[u]>cnt[v])swap(u,v);
        while(sz(s[u])){
            ii j=*s[u].begin();
            Erase(j.se,j.fi);
        }
        while(sz(in[u])){
            Erase(in[u].begin()->fi,u);
        }
        ans+=r[u]*r[v]*2;
        ans+=sz(in[v])*-r[u];
            r[v]+=r[u];
            r[u]=v;
    }
}dsu;
void add(int u,int v){
    v=dsu.acs(v);
    u=dsu.acs(u);
    // cout <<u<<" "<<v<<'\n';
    if(dsu.acs(u)==v||in[v][u])return;
    // cout <<1<<'\n';
    // cout <<u<<" "<<v<<'\n';
    in[v][u]=1;
    ans+=-dsu.r[v];
    s[u].insert({v,u});
    ++cnt[u];
    ++cnt[v];
    auto it=s[v].lower_bound(make_pair(u,-1));
    if(it->fi==u)
        dsu.join(u,v);
}
bool M2;
void solve(){
    cin >> node >> m;
    dsu=DSU(node);
    for(int i=1;i<=m;++i){
        int u,v;
        cin >> u >> v;
        p.em(u,v);
        while(!p.empty()){
            u=p.front().fi;
            v=p.front().se;    
            // cout <<u<<" "<<v<<'\n';        
            p.pop();
            add(u,v);
        }

        cout << ans<<'\n';
    }

}
main()
{
  srand(time(0));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #define task "aws"
    if(fopen(task".inp","r")){
      freopen(task".inp","r",stdin);
      freopen(task".out","w",stdout);
    }
    int t=1;
 //   cin >> t;
while(t--){
    solve();
}
look_memory;
look_time;
}d(u,v);
        }

        cout << ans<<'\n';
    }

}
main()
{
  srand(time(0));
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #define task "aws"
    if(fopen(task".inp","r")){
      freopen(task".inp","r",stdin);
      freopen(task".out","w",stdout);
    }
    int t=1;
 //   cin >> t;
while(t--){
    solve();
}
look_memory;
look_time;
}

Compilation message (stderr)

joitter2.cpp:97:15: error: stray '#' in program
   97 |             ad#include<bits/stdc++.h>
      |               ^
joitter2.cpp: In function 'void solve()':
joitter2.cpp:97:13: error: 'ad' was not declared in this scope; did you mean 'rd'?
   97 |             ad#include<bits/stdc++.h>
      |             ^~
      |             rd
joitter2.cpp:123:22: error: a function-definition is not allowed here before '{' token
  123 | int Rand(int u,int v){
      |                      ^
joitter2.cpp: In member function 'void solve()::DSU::Erase(long long int, long long int)':
joitter2.cpp:142:9: error: use of local variable with automatic storage from containing function
  142 |         ans+=r[v];
      |         ^~~
joitter2.cpp:128:17: note: 'long long int ans' declared here
  128 | int node,m,a[N],ans,cnt[N];
      |                 ^~~
joitter2.cpp:143:9: error: use of local variable with automatic storage from containing function
  143 |         s[acs(u)].erase({v,u});
      |         ^
joitter2.cpp:131:8: note: 'std::set<std::pair<long long int, long long int> > s [100005]' declared here
  131 | set<ii>s[N];
      |        ^
joitter2.cpp:144:9: error: use of local variable with automatic storage from containing function
  144 |         in[v].erase(u);
      |         ^~
joitter2.cpp:130:13: note: 'std::map<long long int, long long int> in [100005]' declared here
  130 | map<int,int>in[N];
      |             ^~
joitter2.cpp:145:9: error: use of local variable with automatic storage from containing function
  145 |         p.em(u,v);
      |         ^
joitter2.cpp:129:10: note: 'std::queue<std::pair<long long int, long long int> > p' declared here
  129 | queue<ii>p;
      |          ^
joitter2.cpp: In member function 'void solve()::DSU::join(long long int, long long int)':
joitter2.cpp:150:12: error: use of local variable with automatic storage from containing function
  150 |         if(cnt[u]>cnt[v])swap(u,v);
      |            ^~~
joitter2.cpp:128:21: note: 'long long int cnt [100005]' declared here
  128 | int node,m,a[N],ans,cnt[N];
      |                     ^~~
joitter2.cpp:150:19: error: use of local variable with automatic storage from containing function
  150 |         if(cnt[u]>cnt[v])swap(u,v);
      |                   ^~~
joitter2.cpp:128:21: note: 'long long int cnt [100005]' declared here
  128 | int node,m,a[N],ans,cnt[N];
      |                     ^~~
joitter2.cpp:151:18: error: use of local variable with automatic storage from containing function
  151 |         while(sz(s[u])){
      |                  ^
joitter2.cpp:101:20: note: in definition of macro 'sz'
  101 | #define sz(a) (int)a.size()
      |                    ^
joitter2.cpp:131:8: note: 'std::set<std::pair<long long int, long long int> > s [100005]' declared here
  131 | set<ii>s[N];
      |        ^
joitter2.cpp:152:19: error: use of local variable with automatic storage from containing function
  152 |             ii j=*s[u].begin();
      |                   ^
joitter2.cpp:131:8: note: 'std::set<std::pair<long long int, long long int> > s [100005]' declared here
  131 | set<ii>s[N];
      |        ^
joitter2.cpp:155:18: error: use of local variable with automatic storage from containing function
  155 |         while(sz(in[u])){
      |                  ^~
joitter2.cpp:101:20: note: in definition of macro 'sz'
  101 | #define sz(a) (int)a.size()
      |                    ^
joitter2.cpp:130:13: note: 'std::map<long long int, long long int> in [100005]' declared here
  130 | map<int,int>in[N];
      |             ^~
joitter2.cpp:156:19: error: use of local variable with automatic storage from containing function
  156 |             Erase(in[u].begin()->fi,u);
      |                   ^~
joitter2.cpp:130:13: note: 'std::map<long long int, long long int> in [100005]' declared here
  130 | map<int,int>in[N];
      |             ^~
joitter2.cpp:158:9: error: use of local variable with automatic storage from containing function
  158 |         ans+=r[u]*r[v]*2;
      |         ^~~
joitter2.cpp:128:17: note: 'long long int ans' declared here
  128 | int node,m,a[N],ans,cnt[N];
      |                 ^~~
joitter2.cpp:159:9: error: use of local variable with automatic storage from containing function
  159 |         ans+=sz(in[v])*-r[u];
      |         ^~~
joitter2.cpp:128:17: note: 'long long int ans' declared here
  128 | int node,m,a[N],ans,cnt[N];
      |                 ^~~
joitter2.cpp:159:17: error: use of local variable with automatic storage from containing function
  159 |         ans+=sz(in[v])*-r[u];
      |                 ^~
joitter2.cpp:101:20: note: in definition of macro 'sz'
  101 | #define sz(a) (int)a.size()
      |                    ^
joitter2.cpp:130:13: note: 'std::map<long long int, long long int> in [100005]' declared here
  130 | map<int,int>in[N];
      |             ^~
joitter2.cpp: In function 'void solve()':
joitter2.cpp:164:22: error: a function-definition is not allowed here before '{' token
  164 | void add(int u,int v){
      |                      ^
joitter2.cpp:181:13: error: a function-definition is not allowed here before '{' token
  181 | void solve(){
      |             ^
joitter2.cpp:200:1: error: 'main' was not declared in this scope; did you mean 'in'?
  200 | main()
      | ^~~~
      | in
joitter2.cpp:218:2: error: 'd' was not declared in this scope
  218 | }d(u,v);
      |  ^
joitter2.cpp: At global scope:
joitter2.cpp:225:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  225 | main()
      | ^~~~
joitter2.cpp: In function 'int main()':
joitter2.cpp:233:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  233 |       freopen(task".inp","r",stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
joitter2.cpp:234:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  234 |       freopen(task".out","w",stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~