QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#78370 | #4894. 学姐买瓜 | bear0131 | 0 | 1ms | 5608kb | C++14 | 2.5kb | 2023-02-18 09:58:10 | 2023-02-18 09:58:12 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
int n;
const int N = 300300, B = 555;
set< pii > st;
int tag[N/B + 10];
int nxt[N], oto[N], odis[N];
void pushdown(int bid){
if(tag[bid] < 0)
return ;
int l = bid*B, r = min((bid+1)*B, n);
for(int i = l; i < r; ++i)
nxt[i] = oto[i] = tag[bid], odis[i] = 1;
tag[bid] = -1;
}
void upd(int tl, int tr, int to){
//cout << "upd " << tl << " " << tr << " " << to << endl;
int bl = tl/B, br = tr/B, bt = to/B;
if(bl == br){
pushdown(bl);
for(int i = tl; i <= tr; ++i){
nxt[i] = to;
if(bt == bl)
oto[i] = oto[to], odis[i] = odis[to]+1;
else
oto[i] = to, odis[i] = 1;
}
} else {
pushdown(bl), pushdown(br);
for(int i = tl; i < (bl+1)*B; ++i)
nxt[i] = oto[i] = to, odis[i] = 1;
for(int i = bl+1; i < br; ++i)
tag[i] = to;
for(int i = br*B; i <= tr; ++i){
nxt[i] = to;
if(bt == br)
oto[i] = oto[to], odis[i] = odis[to]+1;
else
oto[i] = to, odis[i] = 1;
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
memset(tag, -1, sizeof(tag));
int m;
cin >> n >> m;
rep(i, n)
nxt[i] = oto[i] = inf, odis[i] = 0;
st.emplace(-1, -1);
st.emplace(n, n);
while(m--){
int tp;
cin >> tp;
if(tp == 1){
int l, r;
cin >> l >> r;
//for(auto it = st.begin(); it != st.end(); ++it)
// cout << "(" << it->first << " " << it->second << ") ";
//cout << endl;
--l, --r;
auto itr = st.lower_bound(make_pair(l, n+1));
if(itr->second <= r) continue;
--itr;
int updl = itr->first + 1;
while(r <= itr->second){
auto pre = prev(itr);
updl = pre->first + 1;
st.erase(itr);
itr = pre;
}
upd(updl, l, r+1);
st.emplace(l, r);
//rep(i, (n-1)/B+1)
// cout << " " << tag[i]; cout << endl;
//rep(i, n)
// cout << nxt[i] << " "; cout << endl;
//rep(i, n)
// cout << oto[i] << " "; cout << endl;
//rep(i, n)
// cout << odis[i] << " "; cout << endl;
} else {
int l, r;
cin >> l >> r;
--l, --r;
int np = l, ans = 0;
while(1){
int bel = np/B;
if(tag[bel] >= 0){
if(tag[bel] <= r+1)
++ans, np = tag[bel];
else
break;
} else {
if(oto[np] <= r+1)
ans += odis[np], np = oto[np];
else {
if(nxt[np] <= r+1)
++ans, np = nxt[np];
else
break;
}
}
}
cout << ans << "\n";
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5608kb
input:
11 13 2 4 4 1 11 12 1 1 5 1 2 3 1 2 10 2 2 8 1 6 6 2 2 10 1 6 11 2 2 3 2 2 13
output:
0 1 2 1 2 2 2
result:
wrong answer 5th lines differ - expected: '3', found: '2'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%