답안 #262435

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
262435 2020-08-12T23:04:40 Z sckmd Examination (JOI19_examination) C++14
100 / 100
2015 ms 10740 KB
#include <bits/stdc++.h>

using namespace std;
#define MAXN 100005
int a[MAXN];
int b[MAXN];
int n;
int sol[MAXN];

struct que
{
  int x,y,z;
  int id;
};

que qq[MAXN];

bool cmp(que a,que b)
{
  return a.x > b.x;
}
bool cmpp(int x,int y)
{
  return a[x] > a[y];
}
bool cmppp(int x,int y)
{
  return b[x] < b[y];
}

vector <int> idsz;
vector <int> ids;
int pozicija[MAXN];
int BLOCK;
vector <int> moalgo[400];
bool active[MAXN];

void add(int idx)
{
  //idx orig niz
  int mopoz = pozicija[idx];
  int bl = mopoz/BLOCK;
  moalgo[bl].push_back(a[idx]+b[idx]);
  sort(moalgo[bl].begin(),moalgo[bl].end());
  active[idx]=true;
}

int query(int y,int z)
{
  int now = 0;
  while(1)
  {
    if(now >= n)break;
    int realid = ids[now];
    if(b[realid] >= y)break;
    now += BLOCK;
  }
  //cout << now << "\n";
  if(now >= n)
  {
  	int ret=0;
  	for(int j = n-1; j >= max(0,(n-1)-BLOCK); j--)
  	{
  		int realid = ids[j];
  		if(!active[realid])continue;
  		if(a[realid]+b[realid] >= z && b[realid]>=y)ret++;
  	}
  	return ret;
  }
  int ret = 0;
  int blo = now/BLOCK;
  if(blo > 0)
  {
    for(int j = max(0,now-BLOCK); j < now; j++)
    {
      int realid = ids[j];
      if(!active[realid])continue;
      if(a[realid]+b[realid]>=z && b[realid] >= y)ret++;
      //cout << j << " " << realid << "\n";
    }
  }
  //cout << "START BL " << blo << "\n";
  for(;now < n;blo += 1,now+=BLOCK)
  {
    auto it = lower_bound(moalgo[blo].begin(),moalgo[blo].end(),z);
    int pos = it-moalgo[blo].begin();
    ret += moalgo[blo].size()-pos;
    //cout << "BL " << blo << "\n";
  }
  return ret;
}

int main()
{
  ios_base::sync_with_stdio(false);
  int q;
  cin >> n >> q;
  BLOCK = sqrt(n);
  for(int i = 0; i < n; i++)
  {
    cin >> a[i] >> b[i];
    idsz.push_back(i);
    ids.push_back(i);
  }
  for(int i = 0; i < q; i++)
  {
    cin >> qq[i].x >> qq[i].y >> qq[i].z;
    qq[i].id=i;
  }
  sort(qq,qq+q,cmp);
  sort(idsz.begin(),idsz.end(),cmpp);
  sort(ids.begin(),ids.end(),cmppp);
  for(int i = 0; i < ids.size(); i++)pozicija[ids[i]]=i;
  int now = 0;
  for(int i = 0; i < q; i++)
  {
    while(now < n && a[idsz[now]] >= qq[i].x)add(idsz[now]),now++;//,cout << "ADDING " << idsz[now] << "\n";
    //cout << "QUERY " << qq[i].id << "\n";
    sol[qq[i].id]=query(qq[i].y,qq[i].z);
  }
  for(int i = 0; i < q; i++)cout << sol[i] << "\n";
  return 0;
}
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100
*/

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:113:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |   for(int i = 0; i < ids.size(); i++)pozicija[ids[i]]=i;
      |                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 7 ms 640 KB Output is correct
10 Correct 7 ms 640 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 6 ms 768 KB Output is correct
15 Correct 6 ms 640 KB Output is correct
16 Correct 4 ms 640 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1073 ms 5996 KB Output is correct
2 Correct 1117 ms 8156 KB Output is correct
3 Correct 1120 ms 8264 KB Output is correct
4 Correct 988 ms 7668 KB Output is correct
5 Correct 920 ms 7536 KB Output is correct
6 Correct 860 ms 6764 KB Output is correct
7 Correct 1108 ms 8148 KB Output is correct
8 Correct 1226 ms 7964 KB Output is correct
9 Correct 1286 ms 8172 KB Output is correct
10 Correct 697 ms 7296 KB Output is correct
11 Correct 872 ms 7372 KB Output is correct
12 Correct 257 ms 6376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1073 ms 5996 KB Output is correct
2 Correct 1117 ms 8156 KB Output is correct
3 Correct 1120 ms 8264 KB Output is correct
4 Correct 988 ms 7668 KB Output is correct
5 Correct 920 ms 7536 KB Output is correct
6 Correct 860 ms 6764 KB Output is correct
7 Correct 1108 ms 8148 KB Output is correct
8 Correct 1226 ms 7964 KB Output is correct
9 Correct 1286 ms 8172 KB Output is correct
10 Correct 697 ms 7296 KB Output is correct
11 Correct 872 ms 7372 KB Output is correct
12 Correct 257 ms 6376 KB Output is correct
13 Correct 1255 ms 8556 KB Output is correct
14 Correct 1163 ms 8572 KB Output is correct
15 Correct 1083 ms 8296 KB Output is correct
16 Correct 1331 ms 7968 KB Output is correct
17 Correct 900 ms 7852 KB Output is correct
18 Correct 921 ms 6820 KB Output is correct
19 Correct 1297 ms 8612 KB Output is correct
20 Correct 1252 ms 8644 KB Output is correct
21 Correct 1647 ms 8616 KB Output is correct
22 Correct 693 ms 7272 KB Output is correct
23 Correct 868 ms 7404 KB Output is correct
24 Correct 254 ms 6248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 8 ms 640 KB Output is correct
8 Correct 7 ms 640 KB Output is correct
9 Correct 7 ms 640 KB Output is correct
10 Correct 7 ms 640 KB Output is correct
11 Correct 5 ms 640 KB Output is correct
12 Correct 6 ms 640 KB Output is correct
13 Correct 6 ms 640 KB Output is correct
14 Correct 6 ms 768 KB Output is correct
15 Correct 6 ms 640 KB Output is correct
16 Correct 4 ms 640 KB Output is correct
17 Correct 6 ms 640 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 1073 ms 5996 KB Output is correct
20 Correct 1117 ms 8156 KB Output is correct
21 Correct 1120 ms 8264 KB Output is correct
22 Correct 988 ms 7668 KB Output is correct
23 Correct 920 ms 7536 KB Output is correct
24 Correct 860 ms 6764 KB Output is correct
25 Correct 1108 ms 8148 KB Output is correct
26 Correct 1226 ms 7964 KB Output is correct
27 Correct 1286 ms 8172 KB Output is correct
28 Correct 697 ms 7296 KB Output is correct
29 Correct 872 ms 7372 KB Output is correct
30 Correct 257 ms 6376 KB Output is correct
31 Correct 1255 ms 8556 KB Output is correct
32 Correct 1163 ms 8572 KB Output is correct
33 Correct 1083 ms 8296 KB Output is correct
34 Correct 1331 ms 7968 KB Output is correct
35 Correct 900 ms 7852 KB Output is correct
36 Correct 921 ms 6820 KB Output is correct
37 Correct 1297 ms 8612 KB Output is correct
38 Correct 1252 ms 8644 KB Output is correct
39 Correct 1647 ms 8616 KB Output is correct
40 Correct 693 ms 7272 KB Output is correct
41 Correct 868 ms 7404 KB Output is correct
42 Correct 254 ms 6248 KB Output is correct
43 Correct 1277 ms 10540 KB Output is correct
44 Correct 1284 ms 10728 KB Output is correct
45 Correct 1175 ms 10732 KB Output is correct
46 Correct 1343 ms 9064 KB Output is correct
47 Correct 886 ms 9100 KB Output is correct
48 Correct 894 ms 6544 KB Output is correct
49 Correct 1293 ms 10352 KB Output is correct
50 Correct 1615 ms 10740 KB Output is correct
51 Correct 2015 ms 10276 KB Output is correct
52 Correct 693 ms 8880 KB Output is correct
53 Correct 901 ms 8024 KB Output is correct