QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#656500 | #4236. Triangular Logs | chuchu | TL | 234ms | 115248kb | C++14 | 3.2kb | 2024-10-19 13:13:08 | 2024-10-19 13:13:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int mxN = 3e5 + 5;
vector<int> b[mxN], e[mxN];
int er[mxN];
set<int> seg[4 * mxN];
vector<pair<int, int>> pt[mxN];
vector<int> rem_stk;
vector<int> tri[mxN];
void ins(int id, int le, int ri, int i, int l, int r){
if(le >= ri) return;
if(l <= le && r >= ri){
seg[id].insert(i);
return;
}
if(r <= le || l >= ri) return;
int m = (le + ri) / 2;
ins(id << 1, le, m, i, l, r);
ins(id << 1 | 1, m, ri, i, l, r);
}
void ins(int i, int l, int r){
ins(1, 0, mxN - 2, i, l, r);
}
void era(int id, int le, int ri, int i, int l, int r){
if(le >= ri) return;
if(l <= le && r >= ri){
auto it = seg[id].find(i);
seg[id].erase(it);
return;
}
if(r <= le || l >= ri) return;
int m = (le + ri) / 2;
era(id << 1, le, m, i, l, r);
era(id << 1 | 1, m, ri, i, l, r);
}
void era(int i, int l, int r){
era(1, 0, mxN - 2, i, l, r);
}
void go(int id, int le, int ri, int pos, int h){
if(le >= ri) return;
for(int x : seg[id]) if(!er[x]){
tri[x].push_back(h);
if((int)tri[x].size() > 70){
er[x] = 1;
rem_stk.push_back(x);
}
}
if(le + 1 == ri) return;
int m = (le + ri) / 2;
if(pos < m) go(id << 1, le, m, pos, h);
else go(id << 1 | 1, m, ri, pos, h);
}
void go(int p, int h){
go(1, 0, mxN - 2, p, h);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<array<int, 3>> pts(n);
vector<int> x, y;
for(int i = 0; i < n; i++){
for(int j = 0; j < 3; j++) cin >> pts[i][j];
x.push_back(pts[i][0]);
y.push_back(pts[i][1]);
}
vector<array<int, 4>> qry(q);
for(int i = 0; i < q; i++){
for(int j = 0; j < 4; j++) cin >> qry[i][j];
x.push_back(qry[i][0]);
x.push_back(qry[i][2]);
y.push_back(qry[i][1]);
y.push_back(qry[i][3]);
}
sort(x.begin(), x.end());
sort(y.begin(), y.end());
x.resize(unique(x.begin(), x.end()) - x.begin());
y.resize(unique(y.begin(), y.end()) - y.begin());
for(int i = 0; i < n; i++){
pts[i][0] = lower_bound(x.begin(), x.end(), pts[i][0]) - x.begin();
pts[i][1] = lower_bound(y.begin(), y.end(), pts[i][1]) - y.begin();
pt[pts[i][1]].push_back({pts[i][0], pts[i][2]});
}
for(int i = 0; i < q; i++){
qry[i][0] = lower_bound(x.begin(), x.end(), qry[i][0]) - x.begin();
qry[i][1] = lower_bound(y.begin(), y.end(), qry[i][1]) - y.begin();
qry[i][2] = lower_bound(x.begin(), x.end(), qry[i][2]) - x.begin();
qry[i][3] = lower_bound(y.begin(), y.end(), qry[i][3]) - y.begin();
b[qry[i][1]].push_back(i);
e[qry[i][3]].push_back(i);
}
for(int j = 0; j < (int)(y.size()); j++){
for(int ind : b[j]) ins(ind, qry[ind][0], qry[ind][2] + 1);
for(pair<int, int> v : pt[j]){
go(v.first, v.second);
while(!rem_stk.empty()){
int va = rem_stk.back();
era(va, qry[va][0], qry[va][1] + 1);
rem_stk.pop_back();
}
}
for(int ind : e[j]) if(!er[ind]){
er[ind] = 1;
era(ind, qry[ind][0], qry[ind][2] + 1);
}
}
for(int i = 0; i < q; i++){
if((int)tri[i].size() > 70){
cout << "1\n";
continue;
}
sort(tri[i].begin(), tri[i].end());
bool ok = 1;
for(int j = 0; j < (int)(tri[i].size()) - 2; j++){
if(tri[i][j] + tri[i][j + 1] > tri[i][j + 2]){
cout << "1\n";
ok = 0;
break;
}
}
if(ok) cout << "0\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 12ms
memory: 89324kb
input:
9 5 1 3 3 2 3 1 3 3 4 1 2 1 2 2 5 3 2 9 1 1 2 2 1 6 3 1 5 1 1 1 2 1 1 2 2 1 1 1 3 1 2 3 2 1 1 3 3
output:
0 1 0 0 1
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 3ms
memory: 88784kb
input:
481 1 8 6788 8975 24 6552 2668 26 7948 4730 40 531 9805 110 1914 1916 164 7073 3371 165 6293 7756 170 9946 2003 179 9654 1700 215 6447 2229 221 3149 3030 242 1999 6843 242 5764 3163 249 3716 8634 250 6801 9317 260 2741 4273 282 5436 4836 284 3951 6483 288 4812 76 375 9004 5492 380 5627 5929 391 6385...
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 4ms
memory: 88612kb
input:
378 1 62730 50925 80731 92666 77280 61521 29236 67032 7889 35986 96802 8763 13313 49918 83582 51842 66775 47834 2286 12925 41106 39790 6698 15243 65145 56379 68496 35570 809 525 39834 16723 48002 77230 16273 16032 52615 7621 77300 92267 82517 39917 13170 89084 77751 45638 23868 49631 7758 71381 5191...
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 234ms
memory: 115248kb
input:
100000 100000 299999993 206450345 26023928 334281171 300000008 18107965 318653732 299999990 82338399 299999997 393028366 37212808 299999992 208114125 82126189 300000002 303613195 34463905 270033576 299999993 49200970 300000003 249755524 5829381 300000003 367329175 12867359 300000009 337452692 131045...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 100000 lines
Test #5:
score: -100
Time Limit Exceeded
input:
100000 100000 299999990 299999990 40343876 299999990 299999991 75128878 299999990 299999992 54630219 299999990 299999993 2733654 299999990 299999994 46236519 299999990 299999995 98430004 299999990 299999996 48355189 299999990 299999997 85287882 299999990 299999998 83938086 299999990 299999999 739070...