結果
| 問題 |
No.674 n連勤
|
| コンテスト | |
| ユーザー |
夕叢霧香(ゆうむらきりか)
|
| 提出日時 | 2018-04-13 23:24:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,354 bytes |
| コンパイル時間 | 1,282 ms |
| コンパイル使用メモリ | 93,900 KB |
| 最終ジャッジ日時 | 2025-01-05 10:08:06 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 WA * 5 |
ソースコード
#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)
const int W=300;
const int N=W*W;
vector<lint> coord;
map<lint,int> tbl;
lint u[N];
struct iroha{
lint s,e,m;
iroha():s(0),e(0),m(0){}
iroha(lint s,lint e,lint m):s(s),e(e),m(m){}
iroha operator*(const iroha &o){
if(m==-1&&o.m==-1){
return iroha(s+o.s,e+o.e,-1);
}
if(m==-1){
return iroha(s+o.s,o.e,max(o.m,m+o.s));
}
if(o.m==-1){
return iroha(s,e+o.s,max(m,e+o.s));
}
return iroha(s,o.e,max(m,max(o.m,e+o.s)));
}
};
iroha meg[W];
int pop[W];
void tap(int b){
iroha acc(0,0,-1);
rep(i,W){
if(u[b*W+i]){
lint dif=coord[b*W+i+1]-coord[b*W+i];
acc=acc*iroha(dif,dif,-1);
}else{
acc=acc*iroha(0,0,0);
}
}
meg[b]=acc;
}
void update_range(int l,int r){
int b=l/W;
if(pop[b]==W)return;
for(int i=l;i<r;++i){
pop[b]+=1-u[i];
u[i]=1;
}
tap(b);
}
void update(int l,int r){
int lb=(l+W-1)/W;
int rb=r/W;
if(lb>rb){
update_range(l,r);
}else{
update_range(l,lb*W);
update_range(rb*W,r);
for(int i=lb;i<rb;++i){
lint dif=coord[i*W+W]-coord[i*W];
meg[i]=iroha(dif,dif,dif);
pop[i]=W;
}
}
}
iroha query_range(int l,int r){
iroha acc(0,0,0);
for(int i=l;i<r;++i){
lint dif=u[i]?coord[i+1]-coord[i]:0;
acc=acc*(iroha(dif,dif,dif));
}
return acc;
}
lint query(int l,int r){
int lb=(l+W-1)/W;
int rb=r/W;
iroha res;
if(lb>rb){
res=query_range(l,r);
}else{
res=query_range(l,lb*W);
for(int i=lb;i<rb;++i){
res=res*meg[i];
}
res=res*query_range(rb*W,r);
}
return res.m;
}
int main(){
lint d;
int q;
cin>>d>>q;
vector<lint> a(q),b(q);
rep(i,q){
cin>>a[i]>>b[i];
b[i]++;
coord.push_back(a[i]);
coord.push_back(b[i]);
}
coord.push_back(0);
coord.push_back(d);
sort(coord.begin(),coord.end());
coord.erase(unique(coord.begin(),coord.end()),coord.end());
rep(i,coord.size())tbl[coord[i]]=i;
vi ca(q),cb(q);
rep(i,q){
ca[i]=tbl[a[i]];
cb[i]=tbl[b[i]];
}
rep(i,q){
update(ca[i],cb[i]);
cout<<query(0,N)<<endl;
if(0){
rep(j,20)cerr<<" "<<u[j];
cerr<<endl;
}
}
}
夕叢霧香(ゆうむらきりか)