답안 #69165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69165 2018-08-20T08:31:06 Z yusufake 말 (IOI15_horses) C++
100 / 100
995 ms 205268 KB
#include<bits/stdc++.h>
using namespace std;
#include "horses.h"

#define _   int v, int tl, int tr, int l, int r
#define tm  (tl+tr >> 1)
#define sol v+v,tl,tm,l,r
#define sag v+v+1,tm+1,tr,l,r
#define ll long long

const ll mod = 1e9 + 7;
const ll N = 5e5 + 5;
set < int > S;
set < int > :: iterator it;
ll s[N*4],ss[N<<2],X[N],Y[N];

ll up(_, ll x){
    if(tl > r || tr < l) return s[v];
    if(tl == tr) return s[v]=x;
    return s[v] = max(up(sol,x) , up(sag,x));
}
ll qry(_){
    if(tl > r || tr < l) return 0;
    if(tl >= l && tr <= r) return s[v];
    return max(qry(sol) , qry(sag));
}
ll up2(_, ll x){
    if(tl > r || tr < l) return ss[v];
    if(tl == tr) return ss[v]=x;
    return ss[v] = up2(sol,x) * up2(sag,x) % mod;
}
ll qry2(_){
    if(tl > r || tr < l) return 1;
    if(tl >= l && tr <= r) return ss[v];
    return qry2(sol) * qry2(sag) % mod;
}

ll A[77],B[77],l,r,j,n,t,mx;
ll f(){
    r = n-1;
    j = 0;
    t = 1;
    mx = 0;
    for(it = S.end(); it!=S.begin();){
        it--;
        l = *it;
        j++;
        B[j] = qry(1,0,n-1,l,r);
        A[j] = X[l];
        r = l-1;
        t *= X[l];
        if(t >= mod) break;
    }
    if(r > -1 && t < mod){
        l = 0;
        j++;
        B[j] = qry(1,0,n-1,l,r);
        A[j] = X[l];
        r = l-1;
    }
    A[j] = A[j+1] = 1;
    for(; j ; j--){
        A[j] *= A[j+1];
        mx = max(mx , A[j]*B[j]);
    }
    //cout << mx << " ss\n"; 
    return mx%mod*qry2(1,0,n-1,0,r+1)%mod;
}

int updateX(int pos, int val) {
    if(X[pos] == 1 && val > 1) S.insert(pos);
    if(X[pos] > 1 && val == 1) S.erase(pos);
    X[pos] = val;
    up2(1,0,n-1,pos,pos,val);
    return f();
}
int updateY(int pos, int val) {
    Y[pos] = val;
    up(1,0,n-1,pos,pos,val);
    return f();
}
int init(int a, int x[], int y[]){
    int i;
    n = a;
    for(i=0;i<n;i++){
        if(x[i] > 1)
            S.insert(i);
        X[i] = x[i];
        up2(1,0,n-1,i,i,X[i]);
    }
    for(i=0;i<n;i++){
        Y[i] = y[i];
        up(1,0,n-1,i,i,Y[i]);
    }
    return f();
}

Compilation message

horses.cpp: In function 'long long int up(int, int, int, int, int, long long int)':
horses.cpp:6:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define tm  (tl+tr >> 1)
              ~~^~
horses.cpp:7:20: note: in expansion of macro 'tm'
 #define sol v+v,tl,tm,l,r
                    ^~
horses.cpp:20:26: note: in expansion of macro 'sol'
     return s[v] = max(up(sol,x) , up(sag,x));
                          ^~~
horses.cpp:6:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define tm  (tl+tr >> 1)
              ~~^~
horses.cpp:8:19: note: in expansion of macro 'tm'
 #define sag v+v+1,tm+1,tr,l,r
                   ^~
horses.cpp:20:38: note: in expansion of macro 'sag'
     return s[v] = max(up(sol,x) , up(sag,x));
                                      ^~~
horses.cpp: In function 'long long int qry(int, int, int, int, int)':
horses.cpp:6:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define tm  (tl+tr >> 1)
              ~~^~
horses.cpp:7:20: note: in expansion of macro 'tm'
 #define sol v+v,tl,tm,l,r
                    ^~
horses.cpp:25:20: note: in expansion of macro 'sol'
     return max(qry(sol) , qry(sag));
                    ^~~
horses.cpp:6:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define tm  (tl+tr >> 1)
              ~~^~
horses.cpp:8:19: note: in expansion of macro 'tm'
 #define sag v+v+1,tm+1,tr,l,r
                   ^~
horses.cpp:25:31: note: in expansion of macro 'sag'
     return max(qry(sol) , qry(sag));
                               ^~~
horses.cpp: In function 'long long int up2(int, int, int, int, int, long long int)':
horses.cpp:6:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define tm  (tl+tr >> 1)
              ~~^~
horses.cpp:7:20: note: in expansion of macro 'tm'
 #define sol v+v,tl,tm,l,r
                    ^~
horses.cpp:30:24: note: in expansion of macro 'sol'
     return ss[v] = up2(sol,x) * up2(sag,x) % mod;
                        ^~~
horses.cpp:6:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define tm  (tl+tr >> 1)
              ~~^~
horses.cpp:8:19: note: in expansion of macro 'tm'
 #define sag v+v+1,tm+1,tr,l,r
                   ^~
horses.cpp:30:37: note: in expansion of macro 'sag'
     return ss[v] = up2(sol,x) * up2(sag,x) % mod;
                                     ^~~
horses.cpp: In function 'long long int qry2(int, int, int, int, int)':
horses.cpp:6:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define tm  (tl+tr >> 1)
              ~~^~
horses.cpp:7:20: note: in expansion of macro 'tm'
 #define sol v+v,tl,tm,l,r
                    ^~
horses.cpp:35:17: note: in expansion of macro 'sol'
     return qry2(sol) * qry2(sag) % mod;
                 ^~~
horses.cpp:6:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define tm  (tl+tr >> 1)
              ~~^~
horses.cpp:8:19: note: in expansion of macro 'tm'
 #define sag v+v+1,tm+1,tr,l,r
                   ^~
horses.cpp:35:29: note: in expansion of macro 'sag'
     return qry2(sol) * qry2(sag) % mod;
                             ^~~
horses.cpp: In function 'long long int f()':
horses.cpp:48:25: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         B[j] = qry(1,0,n-1,l,r);
                        ~^~
horses.cpp:48:31: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         B[j] = qry(1,0,n-1,l,r);
                               ^
horses.cpp:48:31: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
horses.cpp:57:25: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         B[j] = qry(1,0,n-1,l,r);
                        ~^~
horses.cpp:57:31: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         B[j] = qry(1,0,n-1,l,r);
                               ^
horses.cpp:57:31: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
horses.cpp:67:29: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return mx%mod*qry2(1,0,n-1,0,r+1)%mod;
                            ~^~
horses.cpp:67:35: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return mx%mod*qry2(1,0,n-1,0,r+1)%mod;
                                  ~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:74:14: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     up2(1,0,n-1,pos,pos,val);
             ~^~
horses.cpp:75:13: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return f();
            ~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:79:13: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     up(1,0,n-1,pos,pos,val);
            ~^~
horses.cpp:80:13: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return f();
            ~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:89:18: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         up2(1,0,n-1,i,i,X[i]);
                 ~^~
horses.cpp:93:17: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
         up(1,0,n-1,i,i,Y[i]);
                ~^~
horses.cpp:95:13: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
     return f();
            ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 436 KB Output is correct
5 Correct 3 ms 516 KB Output is correct
6 Correct 2 ms 520 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 604 KB Output is correct
9 Correct 2 ms 608 KB Output is correct
10 Correct 3 ms 612 KB Output is correct
11 Correct 2 ms 616 KB Output is correct
12 Correct 2 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 2 ms 624 KB Output is correct
16 Correct 2 ms 628 KB Output is correct
17 Correct 2 ms 632 KB Output is correct
18 Correct 3 ms 736 KB Output is correct
19 Correct 3 ms 736 KB Output is correct
20 Correct 2 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 796 KB Output is correct
2 Correct 2 ms 796 KB Output is correct
3 Correct 2 ms 796 KB Output is correct
4 Correct 2 ms 796 KB Output is correct
5 Correct 2 ms 796 KB Output is correct
6 Correct 2 ms 796 KB Output is correct
7 Correct 3 ms 796 KB Output is correct
8 Correct 3 ms 796 KB Output is correct
9 Correct 3 ms 796 KB Output is correct
10 Correct 3 ms 796 KB Output is correct
11 Correct 2 ms 796 KB Output is correct
12 Correct 3 ms 796 KB Output is correct
13 Correct 2 ms 796 KB Output is correct
14 Correct 2 ms 796 KB Output is correct
15 Correct 2 ms 796 KB Output is correct
16 Correct 3 ms 796 KB Output is correct
17 Correct 2 ms 796 KB Output is correct
18 Correct 2 ms 796 KB Output is correct
19 Correct 2 ms 796 KB Output is correct
20 Correct 2 ms 796 KB Output is correct
21 Correct 2 ms 796 KB Output is correct
22 Correct 2 ms 796 KB Output is correct
23 Correct 6 ms 796 KB Output is correct
24 Correct 5 ms 924 KB Output is correct
25 Correct 5 ms 964 KB Output is correct
26 Correct 3 ms 1012 KB Output is correct
27 Correct 9 ms 1012 KB Output is correct
28 Correct 5 ms 1056 KB Output is correct
29 Correct 5 ms 1056 KB Output is correct
30 Correct 4 ms 1100 KB Output is correct
31 Correct 8 ms 1100 KB Output is correct
32 Correct 7 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 995 ms 53632 KB Output is correct
2 Correct 641 ms 66316 KB Output is correct
3 Correct 609 ms 69928 KB Output is correct
4 Correct 651 ms 77332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 77332 KB Output is correct
2 Correct 2 ms 77332 KB Output is correct
3 Correct 3 ms 77332 KB Output is correct
4 Correct 2 ms 77332 KB Output is correct
5 Correct 2 ms 77332 KB Output is correct
6 Correct 3 ms 77332 KB Output is correct
7 Correct 2 ms 77332 KB Output is correct
8 Correct 3 ms 77332 KB Output is correct
9 Correct 3 ms 77332 KB Output is correct
10 Correct 2 ms 77332 KB Output is correct
11 Correct 2 ms 77332 KB Output is correct
12 Correct 2 ms 77332 KB Output is correct
13 Correct 3 ms 77332 KB Output is correct
14 Correct 3 ms 77332 KB Output is correct
15 Correct 3 ms 77332 KB Output is correct
16 Correct 2 ms 77332 KB Output is correct
17 Correct 3 ms 77332 KB Output is correct
18 Correct 3 ms 77332 KB Output is correct
19 Correct 2 ms 77332 KB Output is correct
20 Correct 2 ms 77332 KB Output is correct
21 Correct 2 ms 77332 KB Output is correct
22 Correct 3 ms 77332 KB Output is correct
23 Correct 4 ms 77332 KB Output is correct
24 Correct 5 ms 77332 KB Output is correct
25 Correct 4 ms 77332 KB Output is correct
26 Correct 5 ms 77332 KB Output is correct
27 Correct 6 ms 77332 KB Output is correct
28 Correct 6 ms 77332 KB Output is correct
29 Correct 4 ms 77332 KB Output is correct
30 Correct 4 ms 77332 KB Output is correct
31 Correct 6 ms 77332 KB Output is correct
32 Correct 5 ms 77332 KB Output is correct
33 Correct 285 ms 77332 KB Output is correct
34 Correct 301 ms 77332 KB Output is correct
35 Correct 541 ms 95476 KB Output is correct
36 Correct 463 ms 96316 KB Output is correct
37 Correct 316 ms 96316 KB Output is correct
38 Correct 366 ms 96316 KB Output is correct
39 Correct 259 ms 96316 KB Output is correct
40 Correct 456 ms 102248 KB Output is correct
41 Correct 343 ms 102248 KB Output is correct
42 Correct 306 ms 102248 KB Output is correct
43 Correct 472 ms 112788 KB Output is correct
44 Correct 530 ms 119112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 119112 KB Output is correct
2 Correct 2 ms 119112 KB Output is correct
3 Correct 4 ms 119112 KB Output is correct
4 Correct 2 ms 119112 KB Output is correct
5 Correct 2 ms 119112 KB Output is correct
6 Correct 3 ms 119112 KB Output is correct
7 Correct 3 ms 119112 KB Output is correct
8 Correct 2 ms 119112 KB Output is correct
9 Correct 3 ms 119112 KB Output is correct
10 Correct 2 ms 119112 KB Output is correct
11 Correct 2 ms 119112 KB Output is correct
12 Correct 2 ms 119112 KB Output is correct
13 Correct 2 ms 119112 KB Output is correct
14 Correct 2 ms 119112 KB Output is correct
15 Correct 2 ms 119112 KB Output is correct
16 Correct 2 ms 119112 KB Output is correct
17 Correct 3 ms 119112 KB Output is correct
18 Correct 2 ms 119112 KB Output is correct
19 Correct 2 ms 119112 KB Output is correct
20 Correct 3 ms 119112 KB Output is correct
21 Correct 2 ms 119112 KB Output is correct
22 Correct 2 ms 119112 KB Output is correct
23 Correct 4 ms 119112 KB Output is correct
24 Correct 4 ms 119112 KB Output is correct
25 Correct 4 ms 119112 KB Output is correct
26 Correct 4 ms 119112 KB Output is correct
27 Correct 6 ms 119112 KB Output is correct
28 Correct 5 ms 119112 KB Output is correct
29 Correct 3 ms 119112 KB Output is correct
30 Correct 3 ms 119112 KB Output is correct
31 Correct 4 ms 119112 KB Output is correct
32 Correct 6 ms 119112 KB Output is correct
33 Correct 985 ms 120312 KB Output is correct
34 Correct 610 ms 120312 KB Output is correct
35 Correct 722 ms 120312 KB Output is correct
36 Correct 703 ms 120320 KB Output is correct
37 Correct 291 ms 120320 KB Output is correct
38 Correct 270 ms 120320 KB Output is correct
39 Correct 575 ms 120320 KB Output is correct
40 Correct 550 ms 120320 KB Output is correct
41 Correct 358 ms 120320 KB Output is correct
42 Correct 419 ms 120320 KB Output is correct
43 Correct 266 ms 120320 KB Output is correct
44 Correct 545 ms 125332 KB Output is correct
45 Correct 396 ms 125332 KB Output is correct
46 Correct 366 ms 125332 KB Output is correct
47 Correct 489 ms 135704 KB Output is correct
48 Correct 486 ms 142144 KB Output is correct
49 Correct 469 ms 142144 KB Output is correct
50 Correct 468 ms 142144 KB Output is correct
51 Correct 762 ms 165076 KB Output is correct
52 Correct 561 ms 176408 KB Output is correct
53 Correct 911 ms 176408 KB Output is correct
54 Correct 588 ms 176408 KB Output is correct
55 Correct 427 ms 176408 KB Output is correct
56 Correct 565 ms 193620 KB Output is correct
57 Correct 722 ms 193620 KB Output is correct
58 Correct 914 ms 193620 KB Output is correct
59 Correct 476 ms 205268 KB Output is correct