Submission #224581

# Submission time Handle Problem Language Result Execution time Memory
224581 2020-04-18T12:57:56 Z Nightlight Pilot (NOI19_pilot) C++14
14 / 100
60 ms 4728 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define val first
#define id second
using namespace std;

int N, K;
long long sz[1000005];
int par[1000005];
pii H[1000005], Q[1000005];
bitset<1000005> done;
long long ans[1000005], res;

int findpar(int u) {
  if(par[u] == u) return u;
  else {
  	par[u] = findpar(par[u]);
  	return par[u];
  }
}

void merge(int u, int v) {
  u = findpar(u);
  v = findpar(v);
  res -= (sz[u] * (sz[u] + 1)) / 2;
  res -= (sz[v] * (sz[v] + 1)) / 2;
  par[v] = u;
  sz[u] += sz[v];
  res += ((sz[u]  + 1) * sz[u]) / 2;
}

int main() {
//  freopen("inp", "r", stdin);
  scanf("%d %d", &N, &K);
  for(int i = 1; i <= N; i++) {
    scanf("%d", &H[i].val);
    H[i].id = i;
    par[i] = i;
    sz[i] = 1;
  }
  for(int i = 1; i <= K; i++) {
    scanf("%d", &Q[i].val);
    Q[i].id = i;
  }
  sort(H + 1, H + N + 1);
  sort(Q + 1, Q + K + 1);
  int p = 1;
  H[N + 1].val = 1e9;
  Q[K + 1].val = 1e9;
  for(int i = 1; i <= N; i++) {
    int now = H[i].id;
    res += sz[now];
    if(done[findpar(now - 1)]) {
      merge(now - 1, now);
    }
    if(done[findpar(now + 1)]) {
      merge(now, now + 1);
    }
    done[now] = 1;
    while(Q[p].val < H[i + 1].val) {
      ans[Q[p].id] = res;
      p++;
    }
  }
  for(int i = 1; i <= K; i++) {
    printf("%lld\n", ans[i]);
  }
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &N, &K);
   ~~~~~^~~~~~~~~~~~~~~~~
pilot.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &H[i].val);
     ~~~~~^~~~~~~~~~~~~~~~~
pilot.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &Q[i].val);
     ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 5 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 5 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 5 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 5 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 2304 KB Output is correct
2 Correct 34 ms 2304 KB Output is correct
3 Correct 32 ms 2176 KB Output is correct
4 Correct 31 ms 2168 KB Output is correct
5 Correct 32 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 4600 KB Output is correct
2 Correct 58 ms 4728 KB Output is correct
3 Correct 58 ms 4728 KB Output is correct
4 Correct 58 ms 4728 KB Output is correct
5 Correct 58 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 4600 KB Output is correct
2 Incorrect 60 ms 4600 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 5 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 5 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 5 ms 384 KB Output isn't correct
6 Halted 0 ms 0 KB -