Submission #1109358

# Submission time Handle Problem Language Result Execution time Memory
1109358 2024-11-06T14:26:41 Z modwwe Stranded Far From Home (BOI22_island) C++17
100 / 100
178 ms 38588 KB
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while (c < '0' || c > '9')
    {
        c = getchar_unlocked();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + c - '0';
        c = getchar_unlocked();
    }
    return x;
}

void phongbeo();
const int inf = 1e9;
const int mod2 = 1e9 + 7;
const int  mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
    if(x+y>=mod2) x-=mod2;
    if(x+y<0) x+=mod2;
    return x+y;
}
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a, b, c;
};
struct id
{
    int a, b, c, d;
};
struct ie
{
    int a, b, c, d, e;

};

int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int  i, s10, s12,k1,k2,k3,s11,t,lim,w,l,r;
int kk;
int el = 19;

main()
{
    if(fopen(task".inp","r"))
    {
        fin(task);
      //  fou(task);
    }
    NHP
    /// cin>>s1;
    // modwwe
    phongbeo(),down
    // checktime
}
bool cmp(ib a,ib b)
{
    return a.a<b.a;
}
vector<int> v[200001];
bool c[200001];
ib a[200001];
struct dshi
{
    vector<int> v[200001];
    ic dsu[200001];
    void init()
    {
        for(int i=1; i<=n; i++)
            dsu[i]= {1,i,a[i].a},v[i].pb(i);
    }
    int get(int x)
    {
        if(dsu[x].b!=x)return dsu[x].b=get(dsu[x].b);
        return x;
    }
    void noi(int x,int y)
    {
        x=get(x);
        y=get(y);
        if(x==y) return;
        if(v[x].size()<v[y].size())swap(x,y);
        for(auto f:v[y])
            v[x].pb(f);
        if(dsu[x].a<dsu[y].a)swap(v[x],v[y]),swap(x,y);
        dsu[x].a+=dsu[y].a;
        dsu[x].c+=dsu[y].c;
        dsu[y].b=x;
        vector<int>().swap(v[y]);
    }
    void del(int x)
     {
         x=get(x);
         for(auto f:v[x])
            c[f]=1;
                 vector<int>().swap(v[x]);
     }
}ds;
void phongbeo()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)cin>>a[i].a,a[i].b=i;
    for(int i=1; i<=m; i++)
    {
        cin>>l>>r;
        if(a[l].a>=a[r].a)v[l].pb(r);
        else v[r].pb(l);
    }
    ds.init();
    sort(a+1,a+1+n,cmp);
 for(int i=1;i<=n;i++)
    {
        for(auto x:v[a[i].b])
        {
            s2=ds.get(x);
             if(ds.dsu[s2].c<a[i].a)
             {
                 ds.del(s2);
             }
        }
        for(auto x:v[a[i].b])
        {
             ds.noi(a[i].b,x);
        }
    }
     for(int i=1;i<=n;i++)
        cout<<1-c[i];
}

Compilation message

island.cpp:76:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   76 | main()
      | ^~~~
island.cpp: In function 'int main()':
island.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
island.cpp:80:9: note: in expansion of macro 'fin'
   80 |         fin(task);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13648 KB Output is correct
2 Correct 4 ms 13648 KB Output is correct
3 Correct 5 ms 13648 KB Output is correct
4 Correct 5 ms 14072 KB Output is correct
5 Correct 6 ms 13904 KB Output is correct
6 Correct 5 ms 13904 KB Output is correct
7 Correct 4 ms 13904 KB Output is correct
8 Correct 5 ms 13648 KB Output is correct
9 Correct 5 ms 13904 KB Output is correct
10 Correct 5 ms 13916 KB Output is correct
11 Correct 6 ms 13900 KB Output is correct
12 Correct 6 ms 14072 KB Output is correct
13 Correct 5 ms 13904 KB Output is correct
14 Correct 5 ms 13904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13648 KB Output is correct
2 Correct 4 ms 13648 KB Output is correct
3 Correct 97 ms 33096 KB Output is correct
4 Correct 86 ms 34756 KB Output is correct
5 Correct 101 ms 33756 KB Output is correct
6 Correct 102 ms 34260 KB Output is correct
7 Correct 109 ms 34216 KB Output is correct
8 Correct 144 ms 36184 KB Output is correct
9 Correct 106 ms 31936 KB Output is correct
10 Correct 72 ms 29888 KB Output is correct
11 Correct 84 ms 34604 KB Output is correct
12 Correct 117 ms 31952 KB Output is correct
13 Correct 82 ms 32072 KB Output is correct
14 Correct 92 ms 33860 KB Output is correct
15 Correct 99 ms 37188 KB Output is correct
16 Correct 71 ms 36160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 13648 KB Output is correct
2 Correct 137 ms 33924 KB Output is correct
3 Correct 145 ms 34192 KB Output is correct
4 Correct 106 ms 34364 KB Output is correct
5 Correct 104 ms 32300 KB Output is correct
6 Correct 170 ms 34004 KB Output is correct
7 Correct 132 ms 38076 KB Output is correct
8 Correct 133 ms 37948 KB Output is correct
9 Correct 74 ms 36332 KB Output is correct
10 Correct 112 ms 31252 KB Output is correct
11 Correct 135 ms 33184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 13900 KB Output is correct
2 Correct 172 ms 34392 KB Output is correct
3 Correct 178 ms 35216 KB Output is correct
4 Correct 161 ms 35900 KB Output is correct
5 Correct 166 ms 38572 KB Output is correct
6 Correct 148 ms 36532 KB Output is correct
7 Correct 101 ms 35496 KB Output is correct
8 Correct 83 ms 33480 KB Output is correct
9 Correct 80 ms 27708 KB Output is correct
10 Correct 155 ms 37340 KB Output is correct
11 Correct 158 ms 33968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 13648 KB Output is correct
2 Correct 4 ms 13648 KB Output is correct
3 Correct 5 ms 13648 KB Output is correct
4 Correct 5 ms 14072 KB Output is correct
5 Correct 6 ms 13904 KB Output is correct
6 Correct 5 ms 13904 KB Output is correct
7 Correct 4 ms 13904 KB Output is correct
8 Correct 5 ms 13648 KB Output is correct
9 Correct 5 ms 13904 KB Output is correct
10 Correct 5 ms 13916 KB Output is correct
11 Correct 6 ms 13900 KB Output is correct
12 Correct 6 ms 14072 KB Output is correct
13 Correct 5 ms 13904 KB Output is correct
14 Correct 5 ms 13904 KB Output is correct
15 Correct 4 ms 13648 KB Output is correct
16 Correct 4 ms 13648 KB Output is correct
17 Correct 97 ms 33096 KB Output is correct
18 Correct 86 ms 34756 KB Output is correct
19 Correct 101 ms 33756 KB Output is correct
20 Correct 102 ms 34260 KB Output is correct
21 Correct 109 ms 34216 KB Output is correct
22 Correct 144 ms 36184 KB Output is correct
23 Correct 106 ms 31936 KB Output is correct
24 Correct 72 ms 29888 KB Output is correct
25 Correct 84 ms 34604 KB Output is correct
26 Correct 117 ms 31952 KB Output is correct
27 Correct 82 ms 32072 KB Output is correct
28 Correct 92 ms 33860 KB Output is correct
29 Correct 99 ms 37188 KB Output is correct
30 Correct 71 ms 36160 KB Output is correct
31 Correct 6 ms 13648 KB Output is correct
32 Correct 137 ms 33924 KB Output is correct
33 Correct 145 ms 34192 KB Output is correct
34 Correct 106 ms 34364 KB Output is correct
35 Correct 104 ms 32300 KB Output is correct
36 Correct 170 ms 34004 KB Output is correct
37 Correct 132 ms 38076 KB Output is correct
38 Correct 133 ms 37948 KB Output is correct
39 Correct 74 ms 36332 KB Output is correct
40 Correct 112 ms 31252 KB Output is correct
41 Correct 135 ms 33184 KB Output is correct
42 Correct 5 ms 13900 KB Output is correct
43 Correct 172 ms 34392 KB Output is correct
44 Correct 178 ms 35216 KB Output is correct
45 Correct 161 ms 35900 KB Output is correct
46 Correct 166 ms 38572 KB Output is correct
47 Correct 148 ms 36532 KB Output is correct
48 Correct 101 ms 35496 KB Output is correct
49 Correct 83 ms 33480 KB Output is correct
50 Correct 80 ms 27708 KB Output is correct
51 Correct 155 ms 37340 KB Output is correct
52 Correct 158 ms 33968 KB Output is correct
53 Correct 5 ms 13648 KB Output is correct
54 Correct 4 ms 13648 KB Output is correct
55 Correct 4 ms 13648 KB Output is correct
56 Correct 5 ms 13816 KB Output is correct
57 Correct 5 ms 13904 KB Output is correct
58 Correct 5 ms 13752 KB Output is correct
59 Correct 5 ms 13916 KB Output is correct
60 Correct 4 ms 13648 KB Output is correct
61 Correct 5 ms 13904 KB Output is correct
62 Correct 5 ms 13904 KB Output is correct
63 Correct 5 ms 13904 KB Output is correct
64 Correct 5 ms 13904 KB Output is correct
65 Correct 4 ms 13840 KB Output is correct
66 Correct 4 ms 13904 KB Output is correct
67 Correct 101 ms 33096 KB Output is correct
68 Correct 91 ms 34756 KB Output is correct
69 Correct 108 ms 33836 KB Output is correct
70 Correct 112 ms 34384 KB Output is correct
71 Correct 112 ms 34104 KB Output is correct
72 Correct 141 ms 36440 KB Output is correct
73 Correct 87 ms 31816 KB Output is correct
74 Correct 77 ms 29828 KB Output is correct
75 Correct 91 ms 34680 KB Output is correct
76 Correct 123 ms 32072 KB Output is correct
77 Correct 120 ms 32324 KB Output is correct
78 Correct 102 ms 33876 KB Output is correct
79 Correct 102 ms 37188 KB Output is correct
80 Correct 74 ms 36164 KB Output is correct
81 Correct 167 ms 34060 KB Output is correct
82 Correct 158 ms 34116 KB Output is correct
83 Correct 115 ms 34368 KB Output is correct
84 Correct 97 ms 32148 KB Output is correct
85 Correct 170 ms 33864 KB Output is correct
86 Correct 119 ms 38076 KB Output is correct
87 Correct 120 ms 38076 KB Output is correct
88 Correct 118 ms 31032 KB Output is correct
89 Correct 139 ms 33156 KB Output is correct
90 Correct 177 ms 34540 KB Output is correct
91 Correct 148 ms 35160 KB Output is correct
92 Correct 151 ms 35724 KB Output is correct
93 Correct 141 ms 38588 KB Output is correct
94 Correct 144 ms 36680 KB Output is correct
95 Correct 97 ms 35644 KB Output is correct
96 Correct 77 ms 33352 KB Output is correct
97 Correct 67 ms 27720 KB Output is correct
98 Correct 128 ms 37520 KB Output is correct
99 Correct 118 ms 33852 KB Output is correct
100 Correct 34 ms 18512 KB Output is correct
101 Correct 174 ms 35664 KB Output is correct
102 Correct 130 ms 34492 KB Output is correct
103 Correct 138 ms 32300 KB Output is correct
104 Correct 143 ms 34180 KB Output is correct