//0 1 1 0 1
//0 1 0 0 1
//1 0 0 1 1
//0 1 1 0 1
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("avx2")
using namespace std;
#define F first
#define S second
#define pb push_back
#define sze size()
#define all(x) x.begin() , x.end()
#define wall__ cout << "--------------------------------------\n";
#define kids int mid = (tl + tr) >> 1, cl = v << 1, cr = v << 1 | 1
#define file_io freopen("input.cpp", "r", stdin); freopen("output.cpp", "w", stdout);
typedef long long ll;
typedef long double dl;
typedef pair < int , int > pii;
typedef pair < int , ll > pil;
typedef pair < ll , int > pli;
typedef pair < ll , ll > pll;
typedef pair < int , pii > piii;
typedef pair < ll, pll > plll;
const ll N = 2000 + 10;
const ll mod = 1e9 + 7;
const ll inf = 2e16;
const ll INF = 1e9 + 10;
const ll lg = 32;
int n, dp[N], p[N], a[N];
void solve () {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i] >> a[i];
}
if (n > 2000) return;
vector < int > b, c;
for (int i = 1; i <= n; i++) {
while(b.sze > p[i] - 1) {
c.pb(b.back());
b.pop_back();
}
b.pb(a[i]);
while(c.sze) {
b.pb(c.back()); c.pop_back();
}
fill(dp, dp + N, INF); dp[0] = 0;
int ans = 0;
for (int j = 0; j < b.sze; j++) {
int x = b[j];
int it = lower_bound(dp, dp + N, x) - dp;
dp[it] = min(dp[it], x);
ans = max(ans, it);
}
cout << ans << '\n';
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {solve();}
return 0;
}
/*
*/
//shrek is love;
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:47:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | while(b.sze > p[i] - 1) {
| ~~~~~~^~~~~~~~~~
Main.cpp:57:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int j = 0; j < b.sze; j++) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
29 ms |
372 KB |
Output is correct |
4 |
Correct |
48 ms |
340 KB |
Output is correct |
5 |
Correct |
34 ms |
376 KB |
Output is correct |
6 |
Correct |
53 ms |
368 KB |
Output is correct |
7 |
Correct |
33 ms |
364 KB |
Output is correct |
8 |
Correct |
33 ms |
340 KB |
Output is correct |
9 |
Correct |
34 ms |
380 KB |
Output is correct |
10 |
Correct |
33 ms |
340 KB |
Output is correct |
11 |
Correct |
34 ms |
336 KB |
Output is correct |
12 |
Correct |
50 ms |
372 KB |
Output is correct |
13 |
Correct |
58 ms |
456 KB |
Output is correct |
14 |
Correct |
53 ms |
372 KB |
Output is correct |
15 |
Correct |
48 ms |
340 KB |
Output is correct |
16 |
Correct |
54 ms |
364 KB |
Output is correct |
17 |
Correct |
55 ms |
340 KB |
Output is correct |
18 |
Correct |
52 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
29 ms |
372 KB |
Output is correct |
4 |
Correct |
48 ms |
340 KB |
Output is correct |
5 |
Correct |
34 ms |
376 KB |
Output is correct |
6 |
Correct |
53 ms |
368 KB |
Output is correct |
7 |
Correct |
33 ms |
364 KB |
Output is correct |
8 |
Correct |
33 ms |
340 KB |
Output is correct |
9 |
Correct |
34 ms |
380 KB |
Output is correct |
10 |
Correct |
33 ms |
340 KB |
Output is correct |
11 |
Correct |
34 ms |
336 KB |
Output is correct |
12 |
Correct |
50 ms |
372 KB |
Output is correct |
13 |
Correct |
58 ms |
456 KB |
Output is correct |
14 |
Correct |
53 ms |
372 KB |
Output is correct |
15 |
Correct |
48 ms |
340 KB |
Output is correct |
16 |
Correct |
54 ms |
364 KB |
Output is correct |
17 |
Correct |
55 ms |
340 KB |
Output is correct |
18 |
Correct |
52 ms |
340 KB |
Output is correct |
19 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |