QOJ.ac

QOJ

Type: Editorial

Status: Open

Posted by: Hamer_sans

Posted at: 2026-09-09 19:31:31

Last updated: 2026-09-10 21:09:05

Back to Problem

New Editorial for Problem #20016

#include<bits/stdc++.h>
using namespace std;
stack<int> s;
unordered_map<int,bool> vis;
int main(){
    // freopen("test.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        vis.clear();
        int n;
        cin>>n;
        for(int i=1;i<=n;++i){
            char ch;
            cin>>ch;
            int x;
            cin>>x;
            if(ch=='+'){
                while(vis[x]){
                    int t=s.top();
                    s.pop();
                    vis[t]=0;
                    putchar('-');
                }
                s.push(x);
                vis[x]=1;
                putchar('+');
            }
            if(ch=='T') putchar('?');
            if(ch=='F'){
                while(vis[x]){
                    int t=s.top();
                    s.pop();
                    vis[t]=0;
                    putchar('-');
                }
                putchar('?');
            }
        }
        while(!s.empty()){
            int t=s.top();
            s.pop();
            vis[t]=0;
            putchar('-');
        }
        puts("");
    }
    return 0;
}

求调 Wa on #5

Comments

avatar
muchunyunying
对于输入 1 4 + 1 + 2 F 1 T 2 一种构造方案是 +-+?? 你的代码会输出 ++--??