답안 #289621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289621 2020-09-02T19:34:04 Z VROOM_VARUN Bubble Sort 2 (JOI18_bubblesort2) C++14
컴파일 오류
0 ms 0 KB
/*
ID: varunra2
LANG: C++
TASK: bubblesort2
*/

#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif

#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second

const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<ll> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions
int n, q;

map<ll, VII> to;

void coord_comp(VI& a, VI& ind, VI& b) {
  // coordinate compress a and b
  // okay all we need to do is coord compress thats the hard part rn smh
  // debug(n, q);
  for (int i = 0; i < (int)a.size(); i++) {
    a[i] *= (ll)(1e6);
    a[i] += i;
  }

  for (int i = 0; i < (int)ind.size(); i++) {
    b[i] *= (ll)(1e6);
    b[i] += ind[i];
  }

  VI comb;

  for (int i = 0; i < n; i++) {
    to[a[i]].PB(MP(0, i));
  }

  for (int i = 0; i < q; i++) {
    to[b[i]].PB(MP(1, i));
  }

  // debug("inside coord comp");
  // debug("im here");
  // debug(n);
  // debug(q);
  // trav(x, to) { debug(x.x, x.y); }

  int val = 1;

  trav(x, to) {
    trav(y, x.y) {
      if (y.x == 0) {
        a[y.y] = val++;
      } else {
        b[y.y] = val++;
      }
    }
  }

  // debug(val);
  // debug(a);
  // debug(b);
}

VI segtree;
VI lazy;
ll mx;

void push(int l, int r, int node) {
  if (lazy[node] == 0) return;
  segtree[node] += lazy[node];
  if (l != r) {
    lazy[2 * node + 1] += lazy[node];
    lazy[2 * node + 2] += lazy[node];
  }
  lazy[node] = 0;
}

void upd(int tl, int tr, int l, int r, int node, int val) {
  push(l, r, node);
  if (l > tr or r < tl) return;
  if (l > r) return;
  if (l >= tl and r <= tr) {
    lazy[node] += val;
    push(l, r, val);
    return;
  }
  int mid = (l + r) / 2;
  upd(tl, tr, l, mid, 2 * node + 1, val);
  upd(tl, tr, mid + 1, r, 2 * node + 2, val);
  segtree[node] = max(segtree[2 * node + 1], segtree[2 * node + 2]);
  return;
}

inline void upd(int l, int r, int val) { upd(l, r, 0, mx - 1, 0, val); }

int qry(int tl, int tr, int l, int r, int node) {
  push(l, r, node);
  if (l > tr or r < tl) return 0;
  if (l > r) return 0;
  if (l >= tl and r <= tr) {
    return segtree[node];
  }
  int mid = (l + r) / 2;
  return max(qry(tl, tr, l, mid, 2 * node + 1),
             qry(tl, tr, mid + 1, r, 2 * node + 2));
}

inline int qry() {
  // push(0, mx - 5, 0);
  // return segtree[0];
  return qry(0, mx - 5, 0, mx - 5, 0);
}

vector<int> countScans(vector<int>& aa, vector<int>& indind,
                       vector<int>& valval) {
  n = (int)aa.size();
  q = (int)indind.size();
  vector<ll> a;
  vector<ll> ind;
  vector<ll> val;
  for (int i = 0; i < n; i++) {
    a.PB((ll)aa[i]);
  }
  for (int i = 0; i < q; i++) {
    ind.PB((ll)indind[i]);
    val.PB((ll)valval[i]);
  }
  to.clear();

  // find max value of i - #(elements less than a[i])

  // for this we have to calculate #elements less than a[i]

  // how to do this :/
  // debug("in comp");
  // debug(a);
  // debug(n, q);
  coord_comp(a, ind, val);
  // debug(a);
  // debug(a);
  // debug("out comp");
  // debug(val);

  // all elements are now distinct :yay:
  // debug("getting maximum");
  // debug(a);
  // debug(*max_element(all(a)));
  // debug("got max of a");
  // debug(*max_element(all(val)));
  // debug("got max of val");
  mx = max(*max_element(all(a)), *max_element(all(val)));
  // debug("can you not get the max smh");
  mx += 10;

  // debug("got max");

  segtree.resize(4 * mx);
  lazy.resize(4 * mx);
  // debug("resized");
  for (int i = 0; i < 4 * mx; i++) {
    segtree[i] = 0;
    lazy[i] = 0;
  }

  // debug("set to 0");

  for (int i = 0; i < n; i++) {
    // upd(i, i, a[i]);
    // debug("in upd1");
    // debug(a[i]/);
    // debug(mx - 5);
    upd(a[i], a[i], i);
    upd(a[i] + 1, mx - 5, -1);
    // debug("out upd1");
  }

  vector<int> ret(q);

  for (int i = 0; i < q; i++) {
    int nind = ind[i];
    int oval = a[nind];
    int nval = val[i];
    // debug("in");
    upd(oval, oval, -nind);
    upd(oval + 1, mx - 5, 1);
    upd(nval, nval, nind);
    upd(nval + 1, mx - 5, -1);
    // debug("out");
    ret[i] = qry();
  }

  return ret;
}

// int main() {
// #ifndef ONLINE_JUDGE
//   freopen("bubblesort2.in", "r", stdin);
//   freopen("bubblesort2.out", "w", stdout);
// #endif
//   cin.sync_with_stdio(0);
//   cin.tie(0);

//   vector<int> a;
//   vector<int> inds;
//   vector<int> vals;

//   a = {1, 2, 3, 4};
//   inds = {0, 2};
//   vals = {3, 1};
//   // debug("asdf");
//   vector<int> pr = countScans(a, inds, vals);

//   debug(pr);

//   // debug(pr);

//   // debug(to);

//   // debug(a);
//   // debug(vals);

//   // debug(segtree);

//   return 0;
// }

Compilation message

/tmp/ccsagZlP.o: In function `main':
grader.cpp:(.text.startup+0x12b): undefined reference to `countScans(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status