Submission #334970

# Submission time Handle Problem Language Result Execution time Memory
334970 2020-12-10T14:32:08 Z Dymo Pilot (NOI19_pilot) C++14
100 / 100
616 ms 68716 KB
#include<bits/stdc++.h>
using namespace std;


#define pb    push_back
#define eb   emplace_back
#define ll  long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
const ll maxn=1e6+10;
const ll mod =1e9+7 ;
const ll base=3e18;
ll par[maxn];
ll n;
bool dd[maxn];
ll find_par(ll u)
{
  //  cout <<u<<endl;
    if (par[u]<0) return u;
    return par[u]=find_par(par[u]);

}
ll ans=0;
void ad(ll x )
{
   ans+=((x)*(x+1)/2);
}
void er(ll x )
{
  //  cout <<x<<x*(x+1)/2<<endl;

   ans=ans-((x)*(x+1)/2);
   //cout <<x<<endl;
}
void add(ll x)
{
    dd[x]=1;
    if (x==1)
    {
        if (dd[x+1])
        {
           ll t=find_par(x+1);
           er(-par[t]);
           ad(-par[t]+1);
           par[t]+=par[x];
           par[x]=t;
        }
        else
        {
              ans+=(-par[x]);
        }
    }
    else if (x==n)
    {
         if (dd[x-1])
        {
          ll t=find_par(x-1);
          //cout <<t<<" "<<-par[t]<<endl;
        //  cout <<"WTF"<<endl;
            er(-par[t]);

         ad(-par[t]+1);
        //  cout <<t<<endl;
           par[t]+=par[x];
           par[x]=t;
         //  cout <<t<<endl;*/
        }
        else
        {
               ans+=(-par[x]);
        }
    }
    else
    {
        if (dd[x+1]&&dd[x-1])
        {
            ll t=find_par(x+1);
            er(-par[t]);
           par[t]+=par[x];
         //  ad(-par[t]);
           par[x]=t;
           ll h=find_par(x-1);
           er(-par[h]);
           par[t]+=par[h];
           ad(-par[t]);
           par[h]=t;
        }
        else if (dd[x-1])
        {
             ll t=find_par(x-1);
            er(-par[t]);
           ad(-par[t]+1);
           par[t]+=par[x];
           par[x]=t;
        }
        else if (dd[x+1])
        {
            ll t=find_par(x+1);
           er(-par[t]);
           ad(-par[t]+1);
           par[t]+=par[x];
           par[x]=t;
        }
        else
        {
            ans+=(-par[x]);
        }
    }
}
ll ans1[maxn];
pll a[maxn];
pll h[maxn];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("harbingers.in", "r"))
    {
        freopen("harbingers.in", "r", stdin);
        freopen("harbingers.out", "w", stdout);
    }
  ll q;
     cin>> n>>q ;
     for (int i=1;i<=n;i++) par[i]=-1;
     for (int i=1;i<=n;i++)
     {
         cin>>h[i].ff;
         h[i].ss=i;
     }
     sort(h+1,h+n+1);
     for (int i=1;i<=q;i++)
     {
         cin>>a[i].ff;
         a[i].ss=i;
     }
     sort(a+1,a+q+1);
     ll st=1;
     for (int i=1;i<=q;i++)
     {
         while (st<=n&&h[st].ff<=a[i].ff)
         {
            add(h[st].ss);
        //   cout <<st<<" "<<n<<" "<<h[st].ss<<" "<<ans<<endl;
             st++;
         }
      //   cout <<a[i].ss<<" "<<ans<<endl;
         ans1[a[i].ss]=ans;
     }
     for (int i=1;i<=q;i++)
     {
         cout <<ans1[i]<<endl;
     }






}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:123:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  123 |         freopen("harbingers.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pilot.cpp:124:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  124 |         freopen("harbingers.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2816 KB Output is correct
2 Correct 22 ms 2796 KB Output is correct
3 Correct 21 ms 2668 KB Output is correct
4 Correct 20 ms 2540 KB Output is correct
5 Correct 21 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 5740 KB Output is correct
2 Correct 43 ms 5996 KB Output is correct
3 Correct 41 ms 5868 KB Output is correct
4 Correct 41 ms 5996 KB Output is correct
5 Correct 41 ms 5868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 5760 KB Output is correct
2 Correct 44 ms 5868 KB Output is correct
3 Correct 43 ms 5868 KB Output is correct
4 Correct 42 ms 5868 KB Output is correct
5 Correct 44 ms 6124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 22 ms 2816 KB Output is correct
12 Correct 22 ms 2796 KB Output is correct
13 Correct 21 ms 2668 KB Output is correct
14 Correct 20 ms 2540 KB Output is correct
15 Correct 21 ms 2668 KB Output is correct
16 Correct 19 ms 2668 KB Output is correct
17 Correct 19 ms 2796 KB Output is correct
18 Correct 20 ms 2796 KB Output is correct
19 Correct 20 ms 2668 KB Output is correct
20 Correct 20 ms 2668 KB Output is correct
21 Correct 24 ms 2540 KB Output is correct
22 Correct 19 ms 2668 KB Output is correct
23 Correct 20 ms 2796 KB Output is correct
24 Correct 18 ms 2540 KB Output is correct
25 Correct 20 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 22 ms 2816 KB Output is correct
27 Correct 22 ms 2796 KB Output is correct
28 Correct 21 ms 2668 KB Output is correct
29 Correct 20 ms 2540 KB Output is correct
30 Correct 21 ms 2668 KB Output is correct
31 Correct 40 ms 5740 KB Output is correct
32 Correct 43 ms 5996 KB Output is correct
33 Correct 41 ms 5868 KB Output is correct
34 Correct 41 ms 5996 KB Output is correct
35 Correct 41 ms 5868 KB Output is correct
36 Correct 41 ms 5760 KB Output is correct
37 Correct 44 ms 5868 KB Output is correct
38 Correct 43 ms 5868 KB Output is correct
39 Correct 42 ms 5868 KB Output is correct
40 Correct 44 ms 6124 KB Output is correct
41 Correct 19 ms 2668 KB Output is correct
42 Correct 19 ms 2796 KB Output is correct
43 Correct 20 ms 2796 KB Output is correct
44 Correct 20 ms 2668 KB Output is correct
45 Correct 20 ms 2668 KB Output is correct
46 Correct 24 ms 2540 KB Output is correct
47 Correct 19 ms 2668 KB Output is correct
48 Correct 20 ms 2796 KB Output is correct
49 Correct 18 ms 2540 KB Output is correct
50 Correct 20 ms 2668 KB Output is correct
51 Correct 54 ms 5848 KB Output is correct
52 Correct 50 ms 5740 KB Output is correct
53 Correct 51 ms 5868 KB Output is correct
54 Correct 50 ms 5612 KB Output is correct
55 Correct 51 ms 5740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 0 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 22 ms 2816 KB Output is correct
27 Correct 22 ms 2796 KB Output is correct
28 Correct 21 ms 2668 KB Output is correct
29 Correct 20 ms 2540 KB Output is correct
30 Correct 21 ms 2668 KB Output is correct
31 Correct 40 ms 5740 KB Output is correct
32 Correct 43 ms 5996 KB Output is correct
33 Correct 41 ms 5868 KB Output is correct
34 Correct 41 ms 5996 KB Output is correct
35 Correct 41 ms 5868 KB Output is correct
36 Correct 41 ms 5760 KB Output is correct
37 Correct 44 ms 5868 KB Output is correct
38 Correct 43 ms 5868 KB Output is correct
39 Correct 42 ms 5868 KB Output is correct
40 Correct 44 ms 6124 KB Output is correct
41 Correct 19 ms 2668 KB Output is correct
42 Correct 19 ms 2796 KB Output is correct
43 Correct 20 ms 2796 KB Output is correct
44 Correct 20 ms 2668 KB Output is correct
45 Correct 20 ms 2668 KB Output is correct
46 Correct 24 ms 2540 KB Output is correct
47 Correct 19 ms 2668 KB Output is correct
48 Correct 20 ms 2796 KB Output is correct
49 Correct 18 ms 2540 KB Output is correct
50 Correct 20 ms 2668 KB Output is correct
51 Correct 54 ms 5848 KB Output is correct
52 Correct 50 ms 5740 KB Output is correct
53 Correct 51 ms 5868 KB Output is correct
54 Correct 50 ms 5612 KB Output is correct
55 Correct 51 ms 5740 KB Output is correct
56 Correct 610 ms 67180 KB Output is correct
57 Correct 616 ms 66412 KB Output is correct
58 Correct 572 ms 63084 KB Output is correct
59 Correct 578 ms 64492 KB Output is correct
60 Correct 615 ms 68716 KB Output is correct