답안 #108689

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108689 2019-05-01T04:38:14 Z shoemakerjo Examination (JOI19_examination) C++14
100 / 100
1149 ms 48732 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 100010;
int n, q;
const int bil = 1000000000;
#define pii pair<int, int>
#define pp pair<int, pii>
#define mp make_pair


vector<pp> vals;
set<int>  as, bs;
map<int, int> am, bm;

struct BIT {

  vector<int> mvals; //going to want to merge two lists
  vector<int> csum; //the sum values

  int query(int num) {
    //return csum >= num
    //find the index of it in mvals
    int indo = lower_bound(mvals.begin(), mvals.end(), num) - mvals.begin();
    //maybe we should increase by 1
    // indo++;
    indo = mvals.size()-indo;

    if (num == 100) {
      // cout << " thing: " << indo << endl;
    }

    int res = 0;
    while (indo > 0) {
      res += csum[indo];
      indo -= indo & (-indo);
    }
    return res;
  }

  void update(int num) {
    int indo = lower_bound(mvals.begin(), mvals.end(), num) - mvals.begin();

    // indo++;
    // cout << " --mm--- " << mvals.size() << " :: " << indo << endl;
    indo = mvals.size()-indo;

    // cout << " ---- " << indo << endl;
    if (indo == 0) {
      cout << "weird weird" << endl;
      return;
    }
    while (indo < csum.size()) {
      csum[indo]++;
      indo += (indo) & (-indo);
    }
  }

};

set<int> bstuff[maxn]; //push back the b values each guy stores
BIT bigtree[maxn];

void update(int av, int bv) {

  // cout << "updating " << av << endl;

  av = n-av+1;

  while (av <= n) {

    // cout << "    " << av << endl;
    bigtree[av].update(bv);
    av += av & (-av);
  }
}


int query(int av, int bv) {

  // cout << "doing " << av << endl;

  av = n-av+1;
  int res = 0;
  while (av) {
    // cout << "    " << av << endl;
    res += bigtree[av].query(bv);
    av -= av & (-av);
  }
  return res;
}

void addval(int av, int bv) {

  av = n-av+1;
  // cout << "adding pair " << av << ", " << bv << endl;

  while (av <= n) {
    if (bigtree[av].mvals.size() == 0 ||
      bigtree[av].mvals.back() != bv) {
        bigtree[av].mvals.push_back(bv);
        bigtree[av].csum.push_back(0);
      }

    av += av & (-av);
  }
  // cout << " done adding" << endl;
}

vector<pp> msubs[maxn];
vector<pp> madds[maxn];

int ans[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> q;

  for (int i = 0; i <= n; i++) {
    bigtree[i].csum.push_back(0);
  }

  int av, bv;
  for (int i = 0; i < n; i++) {
    cin >> av >> bv;
    vals.push_back(mp(av+bv, mp(av, bv)));
    as.insert(av);

  }

  int curct = 0;

  vector<pii> nstuff;

  vector<int> acur;
  acur.push_back(-1);


  for (int vv : as) {
    am[vv] = ++curct;
    acur.push_back(vv);
  }

  sort(vals.begin(), vals.end());

  for (int i = 1; i <= n; i++) {
    av = vals[i-1].second.first;
    bv = vals[i-1].second.second;
    vals[i-1] = mp(vals[i-1].first, mp(am[av], bv));
    nstuff.push_back(pii(bv, am[av]));
  }

  sort(nstuff.begin(), nstuff.end());

  for (pii vp : nstuff) {
    av = vp.second;
    bv = vp.first;
    addval(av, bv);
  }

  // for (int i = 1; i <= n; i++) {
  //   cout << i << " : ";
  //   for (int vvv : bigtree[i].mvals) cout << vvv << " ";
  //   cout << endl;
  // }

  int xi, yi, zi;
  for (int i = 1; i <= q; i++) {
    cin >> xi >> yi >> zi;
    pp tempo = mp(zi, mp(-1, -1));
    //want first with this sum
    int indo = lower_bound(vals.begin(), vals.end(), tempo) - vals.begin();

    // cout << "    " << i << "'s indo : " << indo << endl;

    //everything with value >= indo should get me (insert at indo)
    if (indo-1 >= 0) msubs[indo-1].push_back(pp(i, pii(xi, yi)));
    madds[n].push_back(pp(i, pii(xi, yi)));
  }

  //we have the big tree

  for (int i = 0; i <= vals.size(); i++) {
    //insert my value
    if (i != vals.size()) {
      av = vals[i].second.first;
      bv = vals[i].second.second;

      // cout << "UPDATE: " << av << " - " << bv << endl;
      update(av, bv);
    }

    for (pp vp : msubs[i]) {
      int indo = vp.first;
      xi = vp.second.first;
      xi = lower_bound(acur.begin(), acur.end(), xi) - acur.begin();
      yi = vp.second.second;


      // cout << "      on " << i << " : " << indo << " " << query(xi, yi) << endl;

      ans[indo] -= query(xi, yi);
    }
    for (pp vp : madds[i]) {
      int indo = vp.first;
      xi = vp.second.first;
      xi = lower_bound(acur.begin(), acur.end(), xi) - acur.begin();

      yi = vp.second.second;

      ans[indo] += query(xi, yi);

      // cout << xi << " - " << yi << "  ::  " << query(xi, yi) << endl;
    }


  }

  for (int i = 1; i <= q; i++) {
    cout << ans[i] << '\n';
  }

  cout.flush();
}

Compilation message

examination.cpp: In member function 'void BIT::update(int)':
examination.cpp:54:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (indo < csum.size()) {
            ~~~~~^~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:186:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i <= vals.size(); i++) {
                   ~~^~~~~~~~~~~~~~
examination.cpp:188:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (i != vals.size()) {
         ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 14464 KB Output is correct
2 Correct 15 ms 14464 KB Output is correct
3 Correct 16 ms 14464 KB Output is correct
4 Correct 16 ms 14464 KB Output is correct
5 Correct 15 ms 14464 KB Output is correct
6 Correct 18 ms 14464 KB Output is correct
7 Correct 29 ms 15480 KB Output is correct
8 Correct 28 ms 15324 KB Output is correct
9 Correct 30 ms 15352 KB Output is correct
10 Correct 28 ms 15232 KB Output is correct
11 Correct 24 ms 14968 KB Output is correct
12 Correct 20 ms 14668 KB Output is correct
13 Correct 28 ms 15332 KB Output is correct
14 Correct 27 ms 15360 KB Output is correct
15 Correct 35 ms 15352 KB Output is correct
16 Correct 21 ms 14848 KB Output is correct
17 Correct 25 ms 15204 KB Output is correct
18 Correct 19 ms 14848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 729 ms 39140 KB Output is correct
2 Correct 698 ms 39240 KB Output is correct
3 Correct 752 ms 39164 KB Output is correct
4 Correct 349 ms 32776 KB Output is correct
5 Correct 166 ms 25804 KB Output is correct
6 Correct 109 ms 22812 KB Output is correct
7 Correct 616 ms 39084 KB Output is correct
8 Correct 660 ms 39220 KB Output is correct
9 Correct 636 ms 38964 KB Output is correct
10 Correct 111 ms 25448 KB Output is correct
11 Correct 252 ms 31788 KB Output is correct
12 Correct 84 ms 23024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 729 ms 39140 KB Output is correct
2 Correct 698 ms 39240 KB Output is correct
3 Correct 752 ms 39164 KB Output is correct
4 Correct 349 ms 32776 KB Output is correct
5 Correct 166 ms 25804 KB Output is correct
6 Correct 109 ms 22812 KB Output is correct
7 Correct 616 ms 39084 KB Output is correct
8 Correct 660 ms 39220 KB Output is correct
9 Correct 636 ms 38964 KB Output is correct
10 Correct 111 ms 25448 KB Output is correct
11 Correct 252 ms 31788 KB Output is correct
12 Correct 84 ms 23024 KB Output is correct
13 Correct 898 ms 41652 KB Output is correct
14 Correct 983 ms 41452 KB Output is correct
15 Correct 644 ms 39344 KB Output is correct
16 Correct 416 ms 35224 KB Output is correct
17 Correct 273 ms 28012 KB Output is correct
18 Correct 103 ms 24940 KB Output is correct
19 Correct 932 ms 41564 KB Output is correct
20 Correct 838 ms 41552 KB Output is correct
21 Correct 850 ms 41512 KB Output is correct
22 Correct 144 ms 25452 KB Output is correct
23 Correct 289 ms 31656 KB Output is correct
24 Correct 134 ms 22892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 14464 KB Output is correct
2 Correct 15 ms 14464 KB Output is correct
3 Correct 16 ms 14464 KB Output is correct
4 Correct 16 ms 14464 KB Output is correct
5 Correct 15 ms 14464 KB Output is correct
6 Correct 18 ms 14464 KB Output is correct
7 Correct 29 ms 15480 KB Output is correct
8 Correct 28 ms 15324 KB Output is correct
9 Correct 30 ms 15352 KB Output is correct
10 Correct 28 ms 15232 KB Output is correct
11 Correct 24 ms 14968 KB Output is correct
12 Correct 20 ms 14668 KB Output is correct
13 Correct 28 ms 15332 KB Output is correct
14 Correct 27 ms 15360 KB Output is correct
15 Correct 35 ms 15352 KB Output is correct
16 Correct 21 ms 14848 KB Output is correct
17 Correct 25 ms 15204 KB Output is correct
18 Correct 19 ms 14848 KB Output is correct
19 Correct 729 ms 39140 KB Output is correct
20 Correct 698 ms 39240 KB Output is correct
21 Correct 752 ms 39164 KB Output is correct
22 Correct 349 ms 32776 KB Output is correct
23 Correct 166 ms 25804 KB Output is correct
24 Correct 109 ms 22812 KB Output is correct
25 Correct 616 ms 39084 KB Output is correct
26 Correct 660 ms 39220 KB Output is correct
27 Correct 636 ms 38964 KB Output is correct
28 Correct 111 ms 25448 KB Output is correct
29 Correct 252 ms 31788 KB Output is correct
30 Correct 84 ms 23024 KB Output is correct
31 Correct 898 ms 41652 KB Output is correct
32 Correct 983 ms 41452 KB Output is correct
33 Correct 644 ms 39344 KB Output is correct
34 Correct 416 ms 35224 KB Output is correct
35 Correct 273 ms 28012 KB Output is correct
36 Correct 103 ms 24940 KB Output is correct
37 Correct 932 ms 41564 KB Output is correct
38 Correct 838 ms 41552 KB Output is correct
39 Correct 850 ms 41512 KB Output is correct
40 Correct 144 ms 25452 KB Output is correct
41 Correct 289 ms 31656 KB Output is correct
42 Correct 134 ms 22892 KB Output is correct
43 Correct 1149 ms 48732 KB Output is correct
44 Correct 1137 ms 48652 KB Output is correct
45 Correct 988 ms 48644 KB Output is correct
46 Correct 523 ms 41004 KB Output is correct
47 Correct 328 ms 29932 KB Output is correct
48 Correct 112 ms 25584 KB Output is correct
49 Correct 1095 ms 48560 KB Output is correct
50 Correct 929 ms 48552 KB Output is correct
51 Correct 847 ms 48680 KB Output is correct
52 Correct 184 ms 28004 KB Output is correct
53 Correct 284 ms 37032 KB Output is correct