제출 #796330

#제출 시각아이디문제언어결과실행 시간메모리
796330YassineBenYounesStone Arranging 2 (JOI23_ho_t1)C++17
100 / 100
335 ms17716 KiB
#include<bits/stdc++.h>
typedef long long ll;
#define pii pair<int, int>
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pbds tree<pair<ll, ll>, null_type, less<pair<ll,ll>>,rb_tree_tag, tree_order_statistics_node_update>
using namespace __gnu_pbds;
#define speed ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
////////////////////Only Clear Code//////////////////////////
void usaco_problem(){
    freopen("milkvisits.in", "r", stdin);
    freopen("milkvisits.out", "w", stdout);
}

void init(){
    #ifndef ONLINE_JUDGE
 
freopen("input.txt", "r", stdin);
 
freopen("output.txt", "w", stdout);
 
#endif // ONLINE_JUDGE
}

const int mx = 3e5+5;
const int mxnd = mx*33;
const int LOG = 25;
const ll inf = 1e18;
const ll mod = 1e8;

int arr[mx];

void run_case(){
    int n;cin >> n;
    stack<pii> st;
    for(int i = 0; i < n;i++){
        cin >> arr[i];
    }
    map<int, int> found;
    for(int i = 0; i < n;i++){
        if(!found[arr[i]]){
            st.push({arr[i], i});
            found[arr[i]] = 1;
            continue;
        }
        while(st.top().ff != arr[i]){
            found[st.top().ff] = 0;
            st.pop();
        }
        st.pop();
        st.push({arr[i], i});
    }
    vector<pii> v;
    while(!st.empty()){
        v.push_back({st.top().ss, st.top().ff});
        st.pop();
    }
    sort(v.begin(), v.end());
    int cur = 0;
    for(int i = 0; i < v.size();i++){
        for(int j = cur;j <= v[i].ff;j++){
            arr[j] = v[i].ss;
        }
        cur = v[i].ff+1;
    }
    for(int i = 0; i < n;i++){
        cout << arr[i] << endl;
    }
}

int main(){
    speed;
    int t = 1;
    //cin >> t;
    while(t--){
        run_case();
    }
}

/*
    NEVER GIVE UP!
    DOING SMTHNG IS BETTER THAN DOING NTHNG!!!
    Your Guide when stuck:
    - Continue keyword only after reading the whole input
    - Don't use memset with testcases
    - Check for corner cases(n=1, n=0)
    - Check where you declare n(Be careful of declaring it globally and in main)
*/

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void run_case()':
Main.cpp:63:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for(int i = 0; i < v.size();i++){
      |                    ~~^~~~~~~~~~
Main.cpp: In function 'void usaco_problem()':
Main.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("milkvisits.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen("milkvisits.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void init()':
Main.cpp:21:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 | freopen("input.txt", "r", stdin);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:8: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 | freopen("output.txt", "w", stdout);
      | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...