题解 | #一种消息接收并打印的结构设计#
一种消息接收并打印的结构设计
https://www.nowcoder.com/practice/155238870f834406ba6971dec4825ab6
#include <cstdio>
using namespace std;
const int N = 100001;
bool vis[N];
int main(void) {
int n, x;
scanf("%d", &n);
int now = 1;
for ( int i = 0; i < n; ++i ) {
scanf("%d", &x);
if ( x == now ) {
printf("%d %d\n", now, now );
int t = now + 1;
while ( t <= n && vis[t] ) printf("%d %d\n", t++, now );
now = t;
if ( now > n ) break;
} else vis[x] = true;
}
return 0;
}
using namespace std;
const int N = 100001;
bool vis[N];
int main(void) {
int n, x;
scanf("%d", &n);
int now = 1;
for ( int i = 0; i < n; ++i ) {
scanf("%d", &x);
if ( x == now ) {
printf("%d %d\n", now, now );
int t = now + 1;
while ( t <= n && vis[t] ) printf("%d %d\n", t++, now );
now = t;
if ( now > n ) break;
} else vis[x] = true;
}
return 0;
}