Submission #1095709

# Submission time Handle Problem Language Result Execution time Memory
1095709 2024-10-03T02:51:44 Z modwwe Railway Trip (JOI17_railway_trip) C++17
0 / 100
65 ms 14600 KB
#pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP     ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe  int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime   cerr << (double)clock() / CLOCKS_PER_SEC * 1000  << " ms";
using namespace std;
#define getchar_unlocked getchar

inline int scan()
{
    char c = getchar_unlocked();
    int x = 0;
    while (c < '0' || c > '9')
    {
        c = getchar_unlocked();
    }
    while (c >= '0' && c <= '9')
    {
        x = (x << 1) + (x << 3) + c - '0';
        c = getchar_unlocked();
    }
    return x;
}

void phongbeo();
const int inf = 1e14;
const int mod2 = 1e9 + 7;
const int  mod1 = 998244353;
struct icd
{
    long double a;
    int b;
};
struct ib
{
    int a;
    int b;
};
struct ic
{
    int a, b, c;
};
struct id
{
    int a, b, c, d;
};
struct ie
{
    int a, b, c, d, e;

};

int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, l, r, mid, l2, r2, center;
int  i, s10, s12,k1,k2,s11;
int kk;
int el = 19;
main()
{
    if(fopen(task".inp","r"))
    {
        fin(task);
        fou(task);
    }
    NHP
    /// cin>>s1;
///modwwe
    phongbeo();
    // checktime
}
bool check(int x,ib y)
{
    if(x>y.b||x<y.a) return 0;
    return 1;
}
int a[100001];
ib st[17][100001];
stack<int>s;
void phongbeo()
{
    cin>>n>>k>>m;
    for(int i=1; i<=n; i++)
        cin>>a[i];

    for(int i=1; i<=n; i++)
    {
        while(!s.empty()&&a[i]>a[s.top()]) s.pop();
        if(i==1)st[0][i].a=i;
        else st[0][i].a=s.top();
        s.push(i);
    }
    while(!s.empty())s.pop();
    for(int i=n; i>=1; --i)
    {
        while(!s.empty()&&a[i]>a[s.top()]) s.pop();
        if(i==n) st[0][i].b=i;
        else st[0][i].b=s.top();
        s.push(i);
    }
    for(int i=1; i<17; i++)
        for(int j=1; j<=n; j++)
            st[i][j].a=min(st[i-1][st[i-1][j].a].a,st[i-1][st[i-1][j].b].a),
                    st[i][j].b=max(st[i-1][st[i-1][j].a].b,st[i-1][st[i-1][j].b].b);
    for(int i=1; i<=m; i++)
    {
        cin>>l>>r;
        s4=0;
        l2=l;
        r2=l;
        for(int i=16; i>=0; i--)
        {
            bool de=0;
            bool de2=0;
            if(check(r,st[i][l2]))de=1;
            if(check(r,st[i][r2])) de2=1;
            if(!de&&!de2)
            {
                s2=min(st[i][l2].a,st[i][r2].a);
                s3=max(st[i][l2].b,st[i][r2].b);
                l2=s2;
                r2=s3;
                s4=s4+(1<<i);
            }
        }
         if(a[r]<a[l2]&&a[r]<a[r2]) s4++;
        cout<<s4,down

    }
}

Compilation message

railway_trip.cpp:36:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+14' to '2147483647' [-Woverflow]
   36 | const int inf = 1e14;
      |                 ^~~~
railway_trip.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main()
      | ^~~~
railway_trip.cpp: In function 'int main()':
railway_trip.cpp:12:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
railway_trip.cpp:71:9: note: in expansion of macro 'fin'
   71 |         fin(task);
      |         ^~~
railway_trip.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 | #define fou(x) freopen(x".out","w",stdout)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~
railway_trip.cpp:72:9: note: in expansion of macro 'fou'
   72 |         fou(task);
      |         ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 14600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 14168 KB Output isn't correct
2 Halted 0 ms 0 KB -