Submission #197277

# Submission time Handle Problem Language Result Execution time Memory
197277 2020-01-20T03:30:30 Z quocnguyen1012 Examination (JOI19_examination) C++14
43 / 100
989 ms 153984 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

const int maxn = 5e5 + 5;

class BIT2Dx {
  public:
  const int INF = 2e9;
  int n;
  vector<int> nodes[maxn];
  vector<int> f[maxn];

  void fakeUpdate(int u, int v){
    for (int x = u; x > 0; x -= x & -x)
      nodes[x].push_back(v);
  }

  void fakeGet(int u, int v){
    for (int x = u; x <= n; x += x & -x)
      nodes[x].push_back(v);
  }

  void update(int u, int v){
    for (int x = u; x > 0; x -= x & -x)
      for (int y = upper_bound(nodes[x].begin(), nodes[x].end(), v) - nodes[x].begin(); y > 0; y -= y & -y)
        f[x][y]++;
  }

  int get(int u, int v){
    int res = 0;
    for (int x = u; x <= n; x += x & -x)
      for (int y = lower_bound(nodes[x].begin(), nodes[x].end(), v) - nodes[x].begin() + 1; y <= nodes[x].size(); y += y & -y)
        res += f[x][y];
    return res;
  }
  void init(int _n){
      n = _n;
  }
  void normalize(void){
    for (int i = 1; i <= n; ++i){
      nodes[i].push_back(INF);
      sort(nodes[i].begin(), nodes[i].end());
      f[i].resize(nodes[i].size() + 3);
    }
  }
}ft;

int N, Q;
pair<int, int> stu[maxn];
int ans[maxn];
vector<int> val;

int compress(int x)
{
  return lower_bound(val.begin(), val.end(), x) - val.begin() + 1;
}

class Query
{
  public:
  int A, B, C, id;
}query[maxn];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N >> Q;
  for (int i = 1; i <= N; ++i){
    cin >> stu[i].fi >> stu[i].se;
    val.pb(stu[i].fi); val.pb(stu[i].se); val.pb(stu[i].fi + stu[i].se);
  }
  for (int i = 1; i <= Q; ++i){
    query[i].id = i;
    cin >> query[i].A >> query[i].B >> query[i].C;
    val.pb(query[i].A); val.pb(query[i].B); val.pb(query[i].C);
  }
  sort(val.begin(), val.end()); val.erase(unique(val.begin(), val.end()), val.end());
  ft.init(val.size());
  sort(stu + 1, stu + 1 + N, greater<pair<int, int>>());
  sort(query + 1, query + 1 + N, [&](const Query & x, const Query & y){
    return x.A > y.A;
  });
  int j = 1;
  for (int i = 1; i <= Q; ++i){
    while (j <= N && stu[j].fi >= query[i].A){
      ft.fakeUpdate(compress(stu[j].se), compress(stu[j].fi + stu[j].se));
      ++j;
    }
    ft.fakeGet(compress(query[i].B), compress(query[i].C));
  }
  ft.normalize();
  j = 1;
  for (int i = 1; i <= Q; ++i){
    while (j <= N && stu[j].fi >= query[i].A){
      ft.update(compress(stu[j].se), compress(stu[j].fi + stu[j].se));
      ++j;
    }
    ans[query[i].id] = ft.get(compress(query[i].B), compress(query[i].C));
    //cerr << ft.get(compress(query[i].B), compress(query[i].C));
  }
  for (int i = 1; i <= Q; ++i){
    cout << ans[i] << '\n';
  }
}

Compilation message

examination.cpp: In member function 'int BIT2Dx::get(int, int)':
examination.cpp:39:95: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int y = lower_bound(nodes[x].begin(), nodes[x].end(), v) - nodes[x].begin() + 1; y <= nodes[x].size(); y += y & -y)
                                                                                             ~~^~~~~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:75:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.INP", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
examination.cpp:76:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.OUT", "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23800 KB Output is correct
2 Correct 25 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 25 ms 23800 KB Output is correct
5 Correct 22 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 43 ms 25592 KB Output is correct
8 Correct 44 ms 25596 KB Output is correct
9 Correct 43 ms 25720 KB Output is correct
10 Correct 39 ms 25336 KB Output is correct
11 Correct 40 ms 25364 KB Output is correct
12 Correct 30 ms 24268 KB Output is correct
13 Correct 41 ms 25336 KB Output is correct
14 Correct 39 ms 25336 KB Output is correct
15 Correct 39 ms 25308 KB Output is correct
16 Correct 35 ms 24696 KB Output is correct
17 Correct 28 ms 25080 KB Output is correct
18 Correct 28 ms 24184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 710 ms 53516 KB Output is correct
2 Correct 809 ms 53720 KB Output is correct
3 Correct 709 ms 53700 KB Output is correct
4 Correct 352 ms 50492 KB Output is correct
5 Correct 548 ms 50272 KB Output is correct
6 Correct 153 ms 34440 KB Output is correct
7 Correct 678 ms 53908 KB Output is correct
8 Correct 678 ms 54608 KB Output is correct
9 Correct 607 ms 53832 KB Output is correct
10 Correct 458 ms 49624 KB Output is correct
11 Correct 322 ms 49388 KB Output is correct
12 Correct 125 ms 31840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 710 ms 53516 KB Output is correct
2 Correct 809 ms 53720 KB Output is correct
3 Correct 709 ms 53700 KB Output is correct
4 Correct 352 ms 50492 KB Output is correct
5 Correct 548 ms 50272 KB Output is correct
6 Correct 153 ms 34440 KB Output is correct
7 Correct 678 ms 53908 KB Output is correct
8 Correct 678 ms 54608 KB Output is correct
9 Correct 607 ms 53832 KB Output is correct
10 Correct 458 ms 49624 KB Output is correct
11 Correct 322 ms 49388 KB Output is correct
12 Correct 125 ms 31840 KB Output is correct
13 Correct 989 ms 55304 KB Output is correct
14 Correct 977 ms 53672 KB Output is correct
15 Correct 701 ms 53728 KB Output is correct
16 Correct 690 ms 50668 KB Output is correct
17 Correct 720 ms 50396 KB Output is correct
18 Correct 175 ms 34364 KB Output is correct
19 Correct 948 ms 55120 KB Output is correct
20 Correct 957 ms 54180 KB Output is correct
21 Correct 981 ms 54964 KB Output is correct
22 Correct 527 ms 49812 KB Output is correct
23 Correct 347 ms 49536 KB Output is correct
24 Correct 118 ms 31972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23800 KB Output is correct
2 Correct 25 ms 23800 KB Output is correct
3 Correct 24 ms 23800 KB Output is correct
4 Correct 25 ms 23800 KB Output is correct
5 Correct 22 ms 23800 KB Output is correct
6 Correct 25 ms 23800 KB Output is correct
7 Correct 43 ms 25592 KB Output is correct
8 Correct 44 ms 25596 KB Output is correct
9 Correct 43 ms 25720 KB Output is correct
10 Correct 39 ms 25336 KB Output is correct
11 Correct 40 ms 25364 KB Output is correct
12 Correct 30 ms 24268 KB Output is correct
13 Correct 41 ms 25336 KB Output is correct
14 Correct 39 ms 25336 KB Output is correct
15 Correct 39 ms 25308 KB Output is correct
16 Correct 35 ms 24696 KB Output is correct
17 Correct 28 ms 25080 KB Output is correct
18 Correct 28 ms 24184 KB Output is correct
19 Correct 710 ms 53516 KB Output is correct
20 Correct 809 ms 53720 KB Output is correct
21 Correct 709 ms 53700 KB Output is correct
22 Correct 352 ms 50492 KB Output is correct
23 Correct 548 ms 50272 KB Output is correct
24 Correct 153 ms 34440 KB Output is correct
25 Correct 678 ms 53908 KB Output is correct
26 Correct 678 ms 54608 KB Output is correct
27 Correct 607 ms 53832 KB Output is correct
28 Correct 458 ms 49624 KB Output is correct
29 Correct 322 ms 49388 KB Output is correct
30 Correct 125 ms 31840 KB Output is correct
31 Correct 989 ms 55304 KB Output is correct
32 Correct 977 ms 53672 KB Output is correct
33 Correct 701 ms 53728 KB Output is correct
34 Correct 690 ms 50668 KB Output is correct
35 Correct 720 ms 50396 KB Output is correct
36 Correct 175 ms 34364 KB Output is correct
37 Correct 948 ms 55120 KB Output is correct
38 Correct 957 ms 54180 KB Output is correct
39 Correct 981 ms 54964 KB Output is correct
40 Correct 527 ms 49812 KB Output is correct
41 Correct 347 ms 49536 KB Output is correct
42 Correct 118 ms 31972 KB Output is correct
43 Runtime error 747 ms 153984 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Halted 0 ms 0 KB -