답안 #1098322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098322 2024-10-09T09:34:14 Z modwwe Matryoshka (JOI16_matryoshka) C++17
100 / 100
285 ms 17256 KB
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC optimize("conserve-stack")
#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 = 1e18;
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,k3,s11,t,lim,w;
int kk;
int el = 19;

main()
{
    if(fopen(task".inp","r"))
    {
        fin(task);
        fou(task);
    }
    NHP
    /// cin>>s1;
///modwwe
    phongbeo();
    // checktime
}
ib a[200001];
ic b[200001];
int ans[200001];
vector<int> v;
bool cmp(ib a,ib b)
{
    if(a.b==b.b) return a.a>b.a;
    return a.b<b.b;
}
bool  cmp2(ic a,ic b)
{
    return a.b<b.b;
}
struct seg
{
    ib t[800001];
    void upd(int node,int l,int r,int l1,int x)
    {
        if(l==r)
        {
            t[node].a+=x;
            if(t[node].a!=0) t[node].b=l;
            else t[node].b=0;
            return;
        }
        int mid=l+r>>1;
        if(l1<=mid)
            upd(node<<1,l,mid,l1,x);
        else upd(node<<1|1,mid+1,r,l1,x);
        t[node].b=max(t[node<<1].b,t[node<<1|1].b);
        t[node].a=t[node<<1].a+t[node<<1|1].a;
    }
    int get(int node,int l,int r,int l1,int r1)
    {
        if(l>r1||r<l1||t[node].b==0) return 0;
        if(l>=l1&&r<=r1) return t[node].b;
        int mid=l+r>>1;
        return  max(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1));
    }
    int get2(int node,int l,int r,int l1,int r1 )
    {
        if(l1>r1) return 0;
        if(l>r1||r<l1||!t[node].a) return 0;
        if(l>=l1&&r<=r1) return t[node].a;
        int mid=l+r>>1;
        return get2(node<<1,l,mid,l1,r1)+get2(node<<1|1,mid+1,r,l1,r1);
    }
} st;
void upd(int x)
{
    s3=st.get(1,1,n,1,a[x].a-1);
    if(s3!=0)
        st.upd(1,1,n,s3,-1);
    st.upd(1,1,n,a[x].a,1) ;

}
void phongbeo()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        cin>>a[i].a>>a[i].b,v.pb(a[i].a);
    sort(a+1,a+1+n,cmp);
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    for(int i=1; i<=n; i++)
        a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1;
    for(int i=1; i<=m; i++)
        cin>>b[i].a>>b[i].b,b[i].c=i;
    sort(b+1,b+1+m,cmp2);
    l=1;
    s11=n;
    n=v.size();
    for(int i=1; i<=m; i++)
    {
        while(l<=s11&&a[l].b<=b[i].b)
        {
            upd(l);
            l++;
        }
        s2=lower_bound(v.begin(),v.end(),b[i].a)-v.begin()+1;
        ans[b[i].c]=st.get2(1,1,n,s2,n);
    }
    for(int i=1; i<=m; i++)
        cout<<ans[i],down
    }

Compilation message

matryoshka.cpp:37:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   37 | const int inf = 1e18;
      |                 ^~~~
matryoshka.cpp:69:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   69 | main()
      | ^~~~
matryoshka.cpp: In member function 'void seg::upd(int, int, int, int, int)':
matryoshka.cpp:107:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  107 |         int mid=l+r>>1;
      |                 ~^~
matryoshka.cpp: In member function 'int seg::get(int, int, int, int, int)':
matryoshka.cpp:118:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  118 |         int mid=l+r>>1;
      |                 ~^~
matryoshka.cpp: In member function 'int seg::get2(int, int, int, int, int)':
matryoshka.cpp:126:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  126 |         int mid=l+r>>1;
      |                 ~^~
matryoshka.cpp: In function 'int main()':
matryoshka.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 fin(x) freopen(x".inp","r",stdin)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~
matryoshka.cpp:73:9: note: in expansion of macro 'fin'
   73 |         fin(task);
      |         ^~~
matryoshka.cpp:14:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define fou(x) freopen(x".out","w",stdout)
      |                ~~~~~~~^~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:74:9: note: in expansion of macro 'fou'
   74 |         fou(task);
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 488 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 572 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 448 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 488 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 572 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 238 ms 15028 KB Output is correct
37 Correct 205 ms 14552 KB Output is correct
38 Correct 76 ms 6864 KB Output is correct
39 Correct 122 ms 9228 KB Output is correct
40 Correct 118 ms 9592 KB Output is correct
41 Correct 239 ms 14768 KB Output is correct
42 Correct 75 ms 8652 KB Output is correct
43 Correct 51 ms 8908 KB Output is correct
44 Correct 260 ms 17048 KB Output is correct
45 Correct 285 ms 17092 KB Output is correct
46 Correct 260 ms 17092 KB Output is correct
47 Correct 224 ms 16588 KB Output is correct
48 Correct 222 ms 17256 KB Output is correct
49 Correct 246 ms 16740 KB Output is correct
50 Correct 218 ms 17104 KB Output is correct