제출 #1095452

#제출 시각아이디문제언어결과실행 시간메모리
1095452modwwe유괴 2 (JOI17_abduction2)C++17
100 / 100
552 ms100432 KiB
#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
}
int a[50001];
int b[50001];
struct SPT
{
    int st[16][50001];
    int f;
    void init(int n,int a[])
    {
        f=n;
        for(int i=1; i<=n; i++)
            st[0][i]=a[i];
        for(int i=1; i<16; i++)
            for(int j=1; j+(1<<i)-1<=n; j++)
                st[i][j]=max(st[i-1][j],st[i-1][j+(1<<(i-1))]);
    }
    int get_mx(int l,int r)
    {
        int k=31-__builtin_clz(r-l+1);
        return max(st[k][l],st[k][r-(1<<k)+1]);
    }
    int get_left(int x,int y)
    {
        l2=1;
        r2=x-1;
        while(l2<=r2)
        {
            int mid=l2+r2>>1;
            if(get_mx(mid,x-1)>y)
            {
                l2=mid+1;
            }
            else r2=mid-1;
        }
        return l2-1;
    }
    int get_right(int x,int y)
    {
        l2=x+1;
        r2=f;
        while(l2<=r2)
        {
            int mid=l2+r2>>1;
            if(get_mx(x+1,mid)>y)r2=mid-1;
            else l2=mid+1;
        }
        return r2+1;
    }
} sp[2];
 unordered_map<int,ll>dp[2][50001];
ll calc(int l ,int r,bool c)
 {
      if(l==0||l==n+1||r==0||r==m+1) return -1;
      if(dp[c][l].find(r)!=dp[c][l].end()) return dp[c][l][r];
   long long ss=0;
     if(!c)
     {
  int ss2=sp[0].get_left(l,b[r]);
  int ss3=sp[0].get_right(l,b[r]);
  ss=max(calc(ss2,r,1)+l-ss2,calc(ss3,r,1)+ss3-l);
     }
     else
     {
  int ss2=sp[1].get_left(r,a[l]);
  int ss3=sp[1].get_right(r,a[l]);
   ss=max(calc(l,ss2,0)+r-ss2,calc(l,ss3,0)+ss3-r);
     }
     dp[c][l][r]=ss;
     return ss;
 }
void phongbeo()
{
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++)
        cin>>a[i];
    for(int j=1; j<=m; j++)
        cin>>b[j];
    sp[0].init(n,a);
    sp[1].init(m,b);
    for(int i=1; i<=k; i++)
    {
        cin>>s2>>s3;
        cout<<max(calc(s2,s3,0),calc(s2,s3,1)),down
    }
}

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

abduction2.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;
      |                 ^~~~
abduction2.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main()
      | ^~~~
abduction2.cpp: In member function 'int SPT::get_left(int, int)':
abduction2.cpp:106:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |             int mid=l2+r2>>1;
      |                     ~~^~~
abduction2.cpp: In member function 'int SPT::get_right(int, int)':
abduction2.cpp:121:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  121 |             int mid=l2+r2>>1;
      |                     ~~^~~
abduction2.cpp: In function 'int main()':
abduction2.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)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
abduction2.cpp:71:9: note: in expansion of macro 'fin'
   71 |         fin(task);
      |         ^~~
abduction2.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)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~
abduction2.cpp:72:9: note: in expansion of macro 'fou'
   72 |         fou(task);
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...