# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
334969 | 2020-12-10T14:31:11 Z | Dymo | Pilot (NOI19_pilot) | C++14 | 257 ms | 7380 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=1e5+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
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 364 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 |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 364 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 | 3 ms | 492 KB | Output is correct |
22 | Correct | 3 ms | 492 KB | Output is correct |
23 | Correct | 3 ms | 492 KB | Output is correct |
24 | Correct | 3 ms | 640 KB | Output is correct |
25 | Correct | 4 ms | 492 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 3436 KB | Output is correct |
2 | Correct | 22 ms | 3436 KB | Output is correct |
3 | Correct | 22 ms | 3200 KB | Output is correct |
4 | Correct | 20 ms | 3180 KB | Output is correct |
5 | Correct | 21 ms | 3180 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 228 ms | 6892 KB | Output is correct |
2 | Correct | 248 ms | 7020 KB | Output is correct |
3 | Correct | 255 ms | 7020 KB | Output is correct |
4 | Correct | 237 ms | 7168 KB | Output is correct |
5 | Correct | 235 ms | 6892 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 234 ms | 7020 KB | Output is correct |
2 | Correct | 240 ms | 7212 KB | Output is correct |
3 | Correct | 243 ms | 7148 KB | Output is correct |
4 | Correct | 230 ms | 7148 KB | Output is correct |
5 | Correct | 257 ms | 7380 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 22 ms | 3436 KB | Output is correct |
12 | Correct | 22 ms | 3436 KB | Output is correct |
13 | Correct | 22 ms | 3200 KB | Output is correct |
14 | Correct | 20 ms | 3180 KB | Output is correct |
15 | Correct | 21 ms | 3180 KB | Output is correct |
16 | Correct | 20 ms | 3180 KB | Output is correct |
17 | Correct | 20 ms | 3436 KB | Output is correct |
18 | Correct | 20 ms | 3436 KB | Output is correct |
19 | Correct | 19 ms | 3180 KB | Output is correct |
20 | Correct | 20 ms | 3308 KB | Output is correct |
21 | Correct | 21 ms | 3180 KB | Output is correct |
22 | Correct | 20 ms | 3308 KB | Output is correct |
23 | Correct | 21 ms | 3308 KB | Output is correct |
24 | Correct | 19 ms | 3200 KB | Output is correct |
25 | Correct | 23 ms | 3308 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 364 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 | 3 ms | 492 KB | Output is correct |
22 | Correct | 3 ms | 492 KB | Output is correct |
23 | Correct | 3 ms | 492 KB | Output is correct |
24 | Correct | 3 ms | 640 KB | Output is correct |
25 | Correct | 4 ms | 492 KB | Output is correct |
26 | Correct | 22 ms | 3436 KB | Output is correct |
27 | Correct | 22 ms | 3436 KB | Output is correct |
28 | Correct | 22 ms | 3200 KB | Output is correct |
29 | Correct | 20 ms | 3180 KB | Output is correct |
30 | Correct | 21 ms | 3180 KB | Output is correct |
31 | Correct | 228 ms | 6892 KB | Output is correct |
32 | Correct | 248 ms | 7020 KB | Output is correct |
33 | Correct | 255 ms | 7020 KB | Output is correct |
34 | Correct | 237 ms | 7168 KB | Output is correct |
35 | Correct | 235 ms | 6892 KB | Output is correct |
36 | Correct | 234 ms | 7020 KB | Output is correct |
37 | Correct | 240 ms | 7212 KB | Output is correct |
38 | Correct | 243 ms | 7148 KB | Output is correct |
39 | Correct | 230 ms | 7148 KB | Output is correct |
40 | Correct | 257 ms | 7380 KB | Output is correct |
41 | Correct | 20 ms | 3180 KB | Output is correct |
42 | Correct | 20 ms | 3436 KB | Output is correct |
43 | Correct | 20 ms | 3436 KB | Output is correct |
44 | Correct | 19 ms | 3180 KB | Output is correct |
45 | Correct | 20 ms | 3308 KB | Output is correct |
46 | Correct | 21 ms | 3180 KB | Output is correct |
47 | Correct | 20 ms | 3308 KB | Output is correct |
48 | Correct | 21 ms | 3308 KB | Output is correct |
49 | Correct | 19 ms | 3200 KB | Output is correct |
50 | Correct | 23 ms | 3308 KB | Output is correct |
51 | Correct | 256 ms | 7096 KB | Output is correct |
52 | Correct | 250 ms | 6892 KB | Output is correct |
53 | Correct | 247 ms | 7020 KB | Output is correct |
54 | Correct | 247 ms | 7020 KB | Output is correct |
55 | Correct | 247 ms | 7020 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | 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 | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 384 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 384 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 384 KB | Output is correct |
16 | Correct | 1 ms | 364 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 | 3 ms | 492 KB | Output is correct |
22 | Correct | 3 ms | 492 KB | Output is correct |
23 | Correct | 3 ms | 492 KB | Output is correct |
24 | Correct | 3 ms | 640 KB | Output is correct |
25 | Correct | 4 ms | 492 KB | Output is correct |
26 | Correct | 22 ms | 3436 KB | Output is correct |
27 | Correct | 22 ms | 3436 KB | Output is correct |
28 | Correct | 22 ms | 3200 KB | Output is correct |
29 | Correct | 20 ms | 3180 KB | Output is correct |
30 | Correct | 21 ms | 3180 KB | Output is correct |
31 | Correct | 228 ms | 6892 KB | Output is correct |
32 | Correct | 248 ms | 7020 KB | Output is correct |
33 | Correct | 255 ms | 7020 KB | Output is correct |
34 | Correct | 237 ms | 7168 KB | Output is correct |
35 | Correct | 235 ms | 6892 KB | Output is correct |
36 | Correct | 234 ms | 7020 KB | Output is correct |
37 | Correct | 240 ms | 7212 KB | Output is correct |
38 | Correct | 243 ms | 7148 KB | Output is correct |
39 | Correct | 230 ms | 7148 KB | Output is correct |
40 | Correct | 257 ms | 7380 KB | Output is correct |
41 | Correct | 20 ms | 3180 KB | Output is correct |
42 | Correct | 20 ms | 3436 KB | Output is correct |
43 | Correct | 20 ms | 3436 KB | Output is correct |
44 | Correct | 19 ms | 3180 KB | Output is correct |
45 | Correct | 20 ms | 3308 KB | Output is correct |
46 | Correct | 21 ms | 3180 KB | Output is correct |
47 | Correct | 20 ms | 3308 KB | Output is correct |
48 | Correct | 21 ms | 3308 KB | Output is correct |
49 | Correct | 19 ms | 3200 KB | Output is correct |
50 | Correct | 23 ms | 3308 KB | Output is correct |
51 | Correct | 256 ms | 7096 KB | Output is correct |
52 | Correct | 250 ms | 6892 KB | Output is correct |
53 | Correct | 247 ms | 7020 KB | Output is correct |
54 | Correct | 247 ms | 7020 KB | Output is correct |
55 | Correct | 247 ms | 7020 KB | Output is correct |
56 | Runtime error | 3 ms | 2668 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
57 | Halted | 0 ms | 0 KB | - |