QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#478258 | #4393. Snatch Groceries | horzward# | AC ✓ | 37ms | 4308kb | C++17 | 1.0kb | 2024-07-14 19:43:02 | 2024-07-14 19:43:03 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define fastio ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
void solve()
{
int n;
cin >> n;
vector<pair<int, int>> v(n);
for(int i = 0; i < n; i++) {
cin >> v[i].second >> v[i].first;
}
if(n == 1) {
cout << "1\n";
return;
}
sort(v.begin(), v.end());
int ans = 0;
for(int i = 0; i < n; i++) {
if(i == 0 && v[i].first < v[i + 1].second) {
ans++;
continue;
}
else if(i == 0) break;
if(i == n - 1 && v[i].second > v[i - 1].first) {
ans++;
continue;
}
else if(i == n - 1) break;
if(v[i].second > v[i - 1].first && v[i].first < v[i + 1].second) ans++;
else break;
}
cout << ans << '\n';
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while(t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 37ms
memory: 4308kb
input:
5 3 1 2 3 4 5 6 3 1 2 3 4 4 5 100000 263324740 263324748 920719069 920719077 82595123 82595132 765796214 765796222 621714954 621714959 77799324 77799332 278166427 278166428 375391536 375391545 856576804 856576812 512542774 512542781 829984452 829984457 302442403 302442404 779239984 779239986 1189173...
output:
3 1 275 5575 10000
result:
ok 5 lines