QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#168767 | #6545. Connect the Dots | PhantomThreshold# | WA | 2ms | 3844kb | C++20 | 1.3kb | 2023-09-08 21:27:37 | 2023-09-08 21:27:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
// cin.tie(0);
int T;
cin>>T;
while(T--)
{
int n,m;
cin>>n>>m;
vector<pair<int,int>> ans;
stack<int> s1,s2;
int c1=0,c2=0;
for(int i=1;i<=n;i++)
{
int x;
cin>>x;
if(c1==0)s1.push(i),c1=x;
else if(c1==x and c2==0)s1.push(i);
else if(c1==x)
{
int u;
while(not s2.empty())
{
u=s2.top();s2.pop();
ans.emplace_back(u,i);
}
s2.push(u);
while(not s1.empty() and s1.top()>u)
{
s1.pop();
}
s1.push(i);
}
else if(c2==0 or c2==x)
{
int u;
while(not s1.empty())
{
u=s1.top();s1.pop();
ans.emplace_back(u,i);
}
s1.push(u);
while(not s2.empty() and s2.top()>u)
{
s2.pop();
}
s2.push(i);
c2=x;
}
else
{
int u,v;
while(not s1.empty())
{
u=s1.top();s1.pop();
ans.emplace_back(u,i);
}
while(not s2.empty())
{
v=s2.top();s2.pop();
ans.emplace_back(v,i);
}
if(u<v)
{
s1.push(u);
s2.push(i);
c2=x;
}
else
{
s1.push(i);
s2.push(v);
c1=x;
}
}
}
cout<<ans.size()<<"\n";
for(auto [u,v]:ans)
cout<<u<<' '<<v<<"\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3588kb
input:
3 4 2 1 1 2 2 4 2 1 2 1 2 3 3 1 2 3
output:
3 2 3 1 3 1 4 4 1 2 2 3 3 4 1 4 3 1 2 1 3 2 3
result:
ok all 3 test passed
Test #2:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
1 2 2 1 2
output:
1 1 2
result:
ok all 1 test passed
Test #3:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
10 5 2 2 2 2 1 2 5 2 2 1 2 1 2 5 2 1 2 2 2 1 5 2 2 1 2 1 1 5 2 1 1 1 2 1 5 2 1 2 2 1 2 5 2 2 1 1 2 2 5 2 2 2 2 1 1 5 2 1 1 2 1 2 5 2 1 2 2 2 1
output:
4 3 4 2 4 1 4 4 5 5 1 2 2 3 3 4 1 4 4 5 4 1 2 1 3 1 4 4 5 5 1 2 2 3 3 4 1 4 1 5 4 3 4 2 4 1 4 4 5 5 1 2 1 3 3 4 4 5 1 5 4 1 2 1 3 3 4 3 5 4 3 4 2 4 1 4 1 5 5 2 3 1 3 3 4 4 5 1 5 4 1 2 1 3 1 4 4 5
result:
ok all 10 test passed
Test #4:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
10 7 2 1 2 1 1 1 2 1 7 2 1 1 2 1 2 1 2 7 2 2 2 1 1 2 1 1 7 2 1 1 1 2 2 1 1 7 2 1 2 2 1 2 2 1 7 2 2 1 2 2 2 2 1 7 2 1 2 1 2 2 2 2 7 2 2 2 1 2 1 2 1 7 2 2 1 1 2 1 2 2 7 2 2 2 1 2 1 1 2
output:
7 1 2 2 3 2 4 2 5 5 6 1 6 6 7 8 2 3 1 3 3 4 4 5 1 5 5 6 6 7 1 7 7 2 3 1 3 1 4 4 5 5 6 1 6 1 7 6 3 4 2 4 1 4 1 5 5 6 5 7 7 1 2 1 3 3 4 4 5 1 5 1 6 6 7 7 1 2 2 3 2 4 2 5 2 6 6 7 1 7 7 1 2 2 3 3 4 1 4 1 5 1 6 1 7 8 2 3 1 3 3 4 4 5 1 5 5 6 6 7 1 7 7 1 2 1 3 3 4 4 5 1 5 5 6 5 7 7 2 3 1 3 3 4 4 5 1 5 1 6 ...
result:
ok all 10 test passed
Test #5:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
10 9 2 1 1 1 2 1 2 2 1 2 9 2 1 2 1 1 2 2 2 2 1 9 2 2 1 2 1 1 2 1 2 1 9 2 1 1 2 1 1 1 1 2 2 9 2 1 1 2 2 1 2 1 2 2 9 2 2 2 1 2 1 2 2 2 2 9 2 1 1 2 2 2 1 2 1 2 9 2 1 1 2 1 1 2 2 2 2 9 2 1 1 1 1 2 1 1 2 1 9 2 2 1 2 2 1 1 2 2 1
output:
10 3 4 2 4 1 4 4 5 5 6 1 6 1 7 7 8 8 9 1 9 9 1 2 2 3 2 4 4 5 1 5 1 6 1 7 1 8 8 9 11 1 2 2 3 3 4 1 4 1 5 5 6 6 7 1 7 7 8 8 9 1 9 9 2 3 1 3 3 4 3 5 3 6 3 7 7 8 1 8 1 9 10 2 3 1 3 1 4 4 5 5 6 1 6 6 7 7 8 1 8 1 9 9 2 3 1 3 3 4 4 5 1 5 5 6 5 7 5 8 5 9 10 2 3 1 3 1 4 1 5 5 6 6 7 1 7 7 8 8 9 1 9 9 2 3 1 3 ...
result:
ok all 10 test passed
Test #6:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
1 5 2 1 1 2 2 1
output:
4 2 3 1 3 1 4 4 5
result:
ok all 1 test passed
Test #7:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
1 7 2 2 1 1 2 1 1 2
output:
7 1 2 1 3 3 4 4 5 1 5 1 6 6 7
result:
ok all 1 test passed
Test #8:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
1 9 2 2 1 1 2 1 1 1 2 2
output:
9 1 2 1 3 3 4 4 5 1 5 1 6 1 7 7 8 7 9
result:
ok all 1 test passed
Test #9:
score: 0
Accepted
time: 1ms
memory: 3844kb
input:
4 20 2 2 1 1 2 1 2 1 1 2 1 1 1 1 2 2 2 1 1 2 2 20 2 2 1 2 2 2 1 1 2 2 2 1 2 2 2 2 1 2 2 1 2 20 2 2 2 1 1 2 2 1 1 1 1 1 2 1 1 2 2 1 2 1 1 20 2 2 1 2 2 2 1 2 2 1 1 1 2 1 2 2 1 2 1 1 2
output:
23 1 2 1 3 3 4 4 5 1 5 5 6 6 7 1 7 1 8 8 9 9 10 1 10 1 11 1 12 1 13 13 14 13 15 13 16 16 17 1 17 1 18 18 19 18 20 23 1 2 2 3 2 4 2 5 5 6 1 6 1 7 7 8 7 9 7 10 10 11 1 11 11 12 11 13 11 14 11 15 15 16 1 16 16 17 16 18 18 19 1 19 19 20 23 2 3 1 3 1 4 4 5 4 6 6 7 1 7 1 8 1 9 1 10 1 11 11 12 12 13 1 13 1...
result:
ok all 4 test passed
Test #10:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
4 100 2 2 2 2 1 2 1 1 1 1 2 2 1 2 2 2 1 2 2 2 2 1 1 1 2 2 1 1 2 1 1 2 1 2 2 1 1 1 2 1 2 1 1 2 1 2 1 2 1 2 1 1 1 1 2 1 1 1 2 2 2 1 2 2 2 1 1 1 2 1 2 1 2 2 1 2 2 1 1 2 1 1 1 1 2 2 1 2 1 1 2 2 1 2 2 1 2 1 2 2 2 100 2 2 1 1 1 1 1 2 2 2 1 2 1 2 2 1 2 2 1 1 1 1 2 1 1 1 2 2 1 1 2 1 1 2 1 1 2 1 1 1 1 1 2 1 ...
output:
126 3 4 2 4 1 4 4 5 5 6 1 6 1 7 1 8 1 9 9 10 9 11 11 12 1 12 12 13 12 14 12 15 15 16 1 16 16 17 16 18 16 19 16 20 20 21 1 21 1 22 1 23 23 24 23 25 25 26 1 26 1 27 27 28 28 29 1 29 1 30 30 31 31 32 1 32 32 33 32 34 34 35 1 35 1 36 1 37 37 38 38 39 1 39 39 40 40 41 1 41 1 42 42 43 43 44 1 44 44 45 45 ...
result:
ok all 4 test passed
Test #11:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
1 100 2 2 2 1 1 2 2 2 1 1 2 1 1 1 2 2 1 2 2 2 1 1 2 2 1 1 2 2 2 1 2 1 1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 2 2 2 2 1 2 1 2 1 1 2 1 1 1 1 1 2 2 2 1 1 2 1 2 2 2 2 1 1 2 2 2 1 1 2 2 2 1 2 2 1 2 1 2 1 2 2 2 1 2 2 2 1 1
output:
125 2 3 1 3 1 4 4 5 4 6 4 7 7 8 1 8 1 9 9 10 10 11 1 11 1 12 1 13 13 14 13 15 15 16 1 16 16 17 16 18 16 19 19 20 1 20 1 21 21 22 21 23 23 24 1 24 1 25 25 26 25 27 25 28 28 29 1 29 29 30 30 31 1 31 1 32 32 33 33 34 1 34 1 35 35 36 35 37 37 38 1 38 38 39 39 40 1 40 1 41 41 42 42 43 1 43 43 44 43 45 45...
result:
ok all 1 test passed
Test #12:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
1 100 2 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1
output:
123 1 2 1 3 3 4 3 5 5 6 1 6 1 7 7 8 7 9 9 10 1 10 1 11 11 12 11 13 13 14 1 14 1 15 15 16 15 17 17 18 1 18 1 19 19 20 19 21 21 22 1 22 1 23 23 24 23 25 25 26 1 26 1 27 27 28 27 29 29 30 1 30 1 31 31 32 31 33 33 34 1 34 1 35 35 36 35 37 37 38 1 38 1 39 39 40 39 41 41 42 1 42 1 43 43 44 43 45 45 46 1 4...
result:
ok all 1 test passed
Test #13:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
1 200 2 1 1 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 2 2 2 ...
output:
208 3 4 2 4 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 13 14 13 15 13 16 13 17 13 18 13 19 13 20 13 21 13 22 13 23 23 24 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 33 34 33 35 33 36 33 37 33 38 33 39 33 40 33 41 33 42 33 43 43 44 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 53 54 53 55 ...
result:
ok all 1 test passed
Test #14:
score: -100
Wrong Answer
time: 1ms
memory: 3560kb
input:
4 7 3 2 2 3 1 3 1 1 7 3 3 1 2 2 3 1 3 7 3 2 1 3 3 2 3 2 7 3 3 2 3 1 3 1 3
output:
9 2 3 1 3 1 4 3 4 1 5 4 5 1 6 5 6 1 7 9 1 2 1 3 2 3 1 4 4 5 5 6 1 6 4 6 6 7 8 1 2 1 3 2 3 1 4 4 5 5 6 1 6 6 7 9 1 2 2 3 3 4 1 4 2 4 4 5 5 6 1 6 6 7
result:
wrong answer output = 8, answer = 9.