# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
518317 |
2022-01-23T11:13:17 Z |
LptN21 |
None (JOI16_matryoshka) |
C++14 |
|
286 ms |
18640 KB |
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL);
#define PI acos(-1.0)
#define eps 1e-9
#define FF first
#define SS second
// VECTOR (6)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() );
// BIT (6)
#define CNTBIT(x) __builtin_popcountll(x)
#define ODDBIT(x) __builtin_parityll(x)
#define MASK(i) (1LL<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, int> ii;
/* CODE BELOW */
const int N = 200000 + 7, M = 1e9 + 7;
const int oo = 1e9 + 7;
const int MOD = 1e9 + 7;
int n, m, k, t;
ii a[N], q[N];
int ans[N], idx[N];
int c[N], mx = 0;
int fen[N];
void update(int p, int v) {
for(;p<=n;p+=p&-p) {
fen[p] = max(fen[p], v);
}
}
int query(int p) {
int ans = 0;
for(;p>0;p-=p&-p) {
ans = max(ans, fen[p]);
}
return ans;
}
bool cmp(int x, int y) {
if(q[x].FF != q[y].FF) {
return q[x].FF < q[y].FF;
}
return q[x].SS < q[y].SS;
}
signed main() {
//freopen("test.inp", "r", stdin);
//freopen("test.out", "w", stdout);
//fastIO;
scanf("%d%d", &n, &m);
vector<int> rrh;
for(int i=1;i<=n;i++) {
scanf("%d%d", &a[i].FF, &a[i].SS);
rrh.pb(a[i].SS); a[i].SS*= -1;
}
sort(a+1, a+n+1), uniq(rrh);
for(int i=1;i<=m;i++) {
scanf("%d%d", &q[i].FF, &q[i].SS);
idx[i] = i;
}
sort(idx+1, idx+m+1, cmp);
for(int j=m, i=n;i>=0;i--) {
while(j>0&&q[idx[j]].FF>a[i].FF) {
int tmp = ub(all(rrh), q[idx[j]].SS) - rrh.begin();
ans[idx[j]] = query(tmp); j--;
}
if(i == 0) break;
a[i].SS = lb(all(rrh), -a[i].SS) - rrh.begin() + 1;
int k = ub(c+1, c+mx+1, a[i].SS) - c;
c[k] = a[i].SS, mx = max(mx, k);
update(a[i].SS, k);
}
for(int i=1;i<=m;i++) {
printf("%d\n", ans[i]);
}
return 0;
}
Compilation message
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:66:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
66 | scanf("%d%d", &a[i].FF, &a[i].SS);
| ~^
| |
| int*
| %lld
matryoshka.cpp:71:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
71 | scanf("%d%d", &q[i].FF, &q[i].SS);
| ~^
| |
| int*
| %lld
matryoshka.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
matryoshka.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d%d", &a[i].FF, &a[i].SS);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | scanf("%d%d", &q[i].FF, &q[i].SS);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
424 KB |
Output is correct |
10 |
Correct |
0 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
424 KB |
Output is correct |
10 |
Correct |
0 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
0 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
0 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
424 KB |
Output is correct |
10 |
Correct |
0 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
0 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
0 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
4 ms |
440 KB |
Output is correct |
24 |
Correct |
3 ms |
464 KB |
Output is correct |
25 |
Correct |
4 ms |
448 KB |
Output is correct |
26 |
Correct |
2 ms |
456 KB |
Output is correct |
27 |
Correct |
2 ms |
452 KB |
Output is correct |
28 |
Correct |
2 ms |
448 KB |
Output is correct |
29 |
Correct |
3 ms |
440 KB |
Output is correct |
30 |
Correct |
2 ms |
444 KB |
Output is correct |
31 |
Correct |
3 ms |
464 KB |
Output is correct |
32 |
Correct |
3 ms |
436 KB |
Output is correct |
33 |
Correct |
2 ms |
464 KB |
Output is correct |
34 |
Correct |
2 ms |
404 KB |
Output is correct |
35 |
Correct |
2 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
0 ms |
336 KB |
Output is correct |
8 |
Correct |
0 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
424 KB |
Output is correct |
10 |
Correct |
0 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
0 ms |
300 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
0 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
4 ms |
440 KB |
Output is correct |
24 |
Correct |
3 ms |
464 KB |
Output is correct |
25 |
Correct |
4 ms |
448 KB |
Output is correct |
26 |
Correct |
2 ms |
456 KB |
Output is correct |
27 |
Correct |
2 ms |
452 KB |
Output is correct |
28 |
Correct |
2 ms |
448 KB |
Output is correct |
29 |
Correct |
3 ms |
440 KB |
Output is correct |
30 |
Correct |
2 ms |
444 KB |
Output is correct |
31 |
Correct |
3 ms |
464 KB |
Output is correct |
32 |
Correct |
3 ms |
436 KB |
Output is correct |
33 |
Correct |
2 ms |
464 KB |
Output is correct |
34 |
Correct |
2 ms |
404 KB |
Output is correct |
35 |
Correct |
2 ms |
464 KB |
Output is correct |
36 |
Correct |
261 ms |
15388 KB |
Output is correct |
37 |
Correct |
180 ms |
14220 KB |
Output is correct |
38 |
Correct |
77 ms |
6316 KB |
Output is correct |
39 |
Correct |
176 ms |
12604 KB |
Output is correct |
40 |
Correct |
183 ms |
13288 KB |
Output is correct |
41 |
Correct |
194 ms |
14140 KB |
Output is correct |
42 |
Correct |
136 ms |
11968 KB |
Output is correct |
43 |
Correct |
107 ms |
12788 KB |
Output is correct |
44 |
Correct |
264 ms |
18188 KB |
Output is correct |
45 |
Correct |
255 ms |
18312 KB |
Output is correct |
46 |
Correct |
241 ms |
18280 KB |
Output is correct |
47 |
Correct |
235 ms |
17968 KB |
Output is correct |
48 |
Correct |
254 ms |
18544 KB |
Output is correct |
49 |
Correct |
286 ms |
17988 KB |
Output is correct |
50 |
Correct |
252 ms |
18640 KB |
Output is correct |