結果
| 問題 |
No.2220 Range Insert & Point Mex
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-03-07 21:12:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,297 bytes |
| コンパイル時間 | 1,310 ms |
| コンパイル使用メモリ | 93,248 KB |
| 最終ジャッジ日時 | 2025-02-11 06:18:54 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 6 WA * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:55:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
55 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:56:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
56 | for (i=0; i<n; i++) scanf("%d %d %d", &rs[i].l, &rs[i].r, &rs[i].a);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:58:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | scanf("%d", &q);
| ~~~~~^~~~~~~~~~
main.cpp:59:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
59 | for (i=0; i<q; i++) scanf("%d", &xs[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;
bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
typedef struct { int l, r, a; } RNode;
RNode rs[100004];
bool mycmp(const RNode& a, const RNode& b) { return a.a<b.a; }
int xs[100004];
typedef struct { int s, e; } GNode;
GNode gs[100004];
bool mycmp2(const GNode& a, const GNode& b) {
if (a.s!=b.s) return a.s<b.s;
return a.e<b.e;
}
int mx, ix[1<<19];
void setm(int s, int e, int v) {
if (s>e) return;
s+=mx; e+=mx;
while(s<=e) {
if (s&1) { ix[s]=min(ix[s], v); s++; }
if ((e&1)==0) { ix[e]=min(ix[e], v); e--; }
s>>=1; e>>=1;
}
}
int findm(int s) {
s+=mx;
int r=ix[s];
while(s) {
r=min(r, ix[s]);
s>>=1;
}
return r;
}
int main() {
int n, i, j, l, r, q, a;
int inf=0x7fffffff, b, k;
int s, e, ki, ns, ne;
scanf("%d", &n);
for (i=0; i<n; i++) scanf("%d %d %d", &rs[i].l, &rs[i].r, &rs[i].a);
sort(rs, rs+n, mycmp);
scanf("%d", &q);
for (i=0; i<q; i++) scanf("%d", &xs[i]);
mx=1; while(mx<=q) mx<<=1;
for (i=0; i<mx+mx; i++) ix[i]=inf;
b=0;
for (i=0; i<n; ) {
a=rs[i].a;
if (b>a) {
setm(0, q-1, b);
break;
}
j=i;
k=0;
while(j<n&&rs[j].a==a) {
l=lower_bound(xs, xs+q, rs[j].l)-xs;
r=upper_bound(xs, xs+q, rs[j].r)-xs; r--;
// printf("%d: %d,%d\n", j, l, r);
if (l<=r) { gs[k].s=l; gs[k].e=r; k++; }
j++;
}
if (k) {
s=gs[0].s; e=gs[0].e;
setm(0, s-1, b);
sort(gs, gs+k, mycmp2);
for (ki=1; ki<k; ki++) {
ns=gs[ki].s; ne=gs[ki].e;
if (ns>e) {
setm(e+1, ns-1, b);
s=ns; e=ne;
} else e=max(e, ne);
}
setm(e+1, q-1, b);
}
i=j;
b++;
}
setm(0, q-1, b);
for (i=0; i<q; i++) {
printf("%d\n", findm(i));
}
return 0;
}