Submission #981949

# Submission time Handle Problem Language Result Execution time Memory
981949 2024-05-13T17:04:24 Z nnin Sequence (APIO23_sequence) C++17
12 / 100
637 ms 74832 KB
#include "sequence.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second

vector<int> ct[500005];
int N;

struct segTree {
  pii seg[4*500005];
  int lazy[4*500005];

  void laze(int i, int l, int r) {
    seg[i] = {seg[i].f+lazy[i], seg[i].s+lazy[i]};
    if(l!=r) {
      lazy[i*2+1] += lazy[i];
      lazy[i*2+2] += lazy[i];
    }
    lazy[i] = 0;
  }

  void build(int i, int l, int r, int val) {
    lazy[i] = 0;
    if(l==r) {
      seg[i].f = seg[i].s = val*l;
      return;
    }
    int m = (l+r)/2;
    build(i*2+1, l, m, val);
    build(i*2+2, m+1, r, val);
    seg[i].f = min(seg[i*2+1].f, seg[i*2+2].f);
    seg[i].s = max(seg[i*2+1].s, seg[i*2+2].s);
  }
  void build(int val) {
    build(0, 0, N, val);
  }

  void update(int i, int l, int r, int wl, int wr, int val) {
    if(wl<=l && wr>=r) lazy[i] += val;
    laze(i, l, r);
    if(wl>r || wr<l || (wl<=l && wr>=r)) return;
    int m = (l+r)/2;
    update(i*2+1, l, m, wl, wr, val);
    update(i*2+2, m+1, r, wl, wr, val);
    seg[i].f = min(seg[i*2+1].f, seg[i*2+2].f);
    seg[i].s = max(seg[i*2+1].s, seg[i*2+2].s);
  }
  void update(int wl, int wr, int val) {
    update(0, 0, N, wl, wr, val);
  }

  pii query(int i, int l, int r, int wl, int wr) {
    laze(i, l, r);
    if(wl>r || wr<l) return {(int)1e9, (int)-1e9};
    if(wl<=l && wr>=r) return seg[i];
    int m = (l+r)/2;
    pii q1 = query(i*2+1, l, m, wl, wr);
    pii q2 = query(i*2+2, m+1, r, wl, wr);
    return {min(q1.f, q2.f), max(q1.s, q2.s)};
  }
  pii query(int wl, int wr) {
    return query(0, 0, N, wl, wr);
  }
} les, mor;

int sequence(int n, std::vector<int> A) {
  N = n;
  for(int i=0;i<N;i++) {
    ct[A[i]].push_back(i+1);
  }
  les.build(-1);
  mor.build(1);
  int ans = 1;
  for(int i=1;i<=N;i++) {
    for(int j:ct[i]) {
      les.update(j, N, 2);
    }
    for(int j=0;j+ans<ct[i].size();j++) {
      while(j+ans<ct[i].size()) {  
        int st = ct[i][j];
        int en = ct[i][j+ans];
        int qles = les.query(en, N).s - les.query(0, st-1).f;
        int qmor = mor.query(en, N).s - les.query(0, st-1).f;
        if(qles>=0 && qmor>=0) ans++;
        else break;
      }
    }
    for(int j:ct[i]) {
      mor.update(j, N, -2);
    }
  }
  return ans;
}

Compilation message

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:80:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     for(int j=0;j+ans<ct[i].size();j++) {
      |                 ~~~~~^~~~~~~~~~~~~
sequence.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |       while(j+ans<ct[i].size()) {
      |             ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 46684 KB Output is correct
2 Correct 8 ms 46820 KB Output is correct
3 Correct 8 ms 46776 KB Output is correct
4 Correct 8 ms 46684 KB Output is correct
5 Incorrect 8 ms 46780 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 46684 KB Output is correct
2 Correct 8 ms 46820 KB Output is correct
3 Correct 8 ms 46776 KB Output is correct
4 Correct 8 ms 46684 KB Output is correct
5 Incorrect 8 ms 46780 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 46684 KB Output is correct
2 Correct 309 ms 68876 KB Output is correct
3 Incorrect 314 ms 68864 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 46820 KB Output is correct
2 Correct 461 ms 61180 KB Output is correct
3 Correct 507 ms 61044 KB Output is correct
4 Correct 529 ms 61188 KB Output is correct
5 Correct 637 ms 61000 KB Output is correct
6 Correct 528 ms 61116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 440 ms 74832 KB Output is correct
2 Correct 432 ms 74588 KB Output is correct
3 Correct 436 ms 74024 KB Output is correct
4 Correct 458 ms 74028 KB Output is correct
5 Correct 430 ms 70688 KB Output is correct
6 Correct 462 ms 70696 KB Output is correct
7 Correct 451 ms 69276 KB Output is correct
8 Incorrect 408 ms 68948 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 46684 KB Output is correct
2 Correct 8 ms 46820 KB Output is correct
3 Correct 8 ms 46776 KB Output is correct
4 Correct 8 ms 46684 KB Output is correct
5 Incorrect 8 ms 46780 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 46684 KB Output is correct
2 Correct 8 ms 46820 KB Output is correct
3 Correct 8 ms 46776 KB Output is correct
4 Correct 8 ms 46684 KB Output is correct
5 Incorrect 8 ms 46780 KB Output isn't correct
6 Halted 0 ms 0 KB -