LibreOJ真是吼啊!

数码

推个式子,把枚举因数转为枚举倍数。然后就发现它是根号分段的。然后每一段算一下就好了。

 #include <cstdio>
#include <cstring> #define R register
typedef long long ll;
struct Data {
ll num[];
inline void clear()
{
memset(num, , << );
}
inline Data operator + (const Data &that) const
{
R Data ret; memcpy(ret.num, num, << );
for (R int i = ; i <= ; ++i) ret.num[i] += that.num[i];
return ret;
}
inline void operator += (const Data &that)
{
for (R int i = ; i <= ; ++i) num[i] += that.num[i];
}
inline Data operator - (const Data &that) const
{
R Data ret; memcpy(ret.num, num, << );
for (R int i = ; i <= ; ++i) ret.num[i] -= that.num[i];
return ret;
}
inline void operator *= (const int &that)
{
for (R int i = ; i <= ; ++i) num[i] *= that;
}
} ;
inline Data calc2(R int N)
{
R ll tmp; R Data ret; ret.clear();
for (tmp = ; tmp - <= N; tmp *= )
for (R int i = ; i <= ; ++i)
ret.num[i] += tmp / ;
tmp /= ;
for (R int i = ; i < (N / tmp); ++i) ret.num[i] += tmp;
ret.num[N / tmp] += N % tmp + ;
// printf("calc2(%d) = \n", N);
// for (R int i = 1; i <= 9; ++i) printf("%lld\n", ret.num[i]);
return ret;
}
inline Data calc(R int N)
{
R Data ret; ret.clear();
for (R int i = , j; i <= N; i = j + )
{
j = N / (N / i);
R Data tmp = calc2(j) - calc2(i - );
tmp *= N / i;
ret += tmp;
}
return ret;
}
int main()
{
R int l, r; scanf("%d%d", &l, &r);
R Data ans = calc(r) - calc(l - );
for (R int i = ; i <= ; ++i)
printf("%lld\n", ans.num[i]);
return ;
}

数码

跳格子

预处理出每个点能不能到终点。然后直接暴搜就好了。

 #include <cstdio>
#include <cstdlib> #define R register
#define maxn 100010
struct Edge {
Edge *next;
int to;
} *last[maxn], e[maxn << ], *ecnt = e;
inline void link(R int a, R int b)
{
*++ecnt = (Edge) {last[a], b}; last[a] = ecnt;
}
int q[maxn], n, a[maxn], b[maxn];
bool arv[maxn], ins[maxn];
char st[maxn];
void dfs(R int x, R int step)
{
if (!arv[x]) return ;
if (x == n)
{
for (R int i = ; i < step; ++i) printf("%c", st[i]); puts("");
exit();
}
if (ins[x])
{
puts("Infinity!");
exit();
}
ins[x] = ;
if (x + a[x] > && x + a[x] <= n)
{
st[step] = 'a';
dfs(x + a[x], step + );
}
if (x + b[x] > && x + b[x] <= n)
{
st[step] = 'b';
dfs(x + b[x], step + );
}
}
int main()
{
scanf("%d", &n);
for (R int i = ; i <= n; ++i) scanf("%d", a + i), i + a[i] > && i + a[i] <= n ? link(i + a[i], i), : ;
for (R int i = ; i <= n; ++i) scanf("%d", b + i), i + b[i] > && i + b[i] <= n ? link(i + b[i], i), : ;
R int head = , tail = ; arv[q[] = n] = ;
while (head < tail)
{
R int now = q[++head];
for (R Edge *iter = last[now]; iter; iter = iter -> next)
if (!arv[iter -> to]) arv[q[++tail] = iter -> to] = ;
}
if (!arv[]) {puts("No solution!"); return ;}
dfs(, );
return ;
}

跳格子

优惠券

一开始傻逼了,以为只要前缀就好了,后来才发现是区间。。。对于每个不满足的条件的左/右括号扔进一个数据结构里,然后每次遇到问号的时候,去消右端点最近的一个括号。然后这个数据结构用堆就够啦~

 #include <cstdio>
#include <vector>
#include <queue> #define R register
#define maxn 500010
int last[maxn], lastt[maxn];
struct Opt {int type, x;} p[maxn];
std::vector<int> v[maxn];
std::priority_queue<int, std::vector<int>, std::greater<int> > q;
int main()
{
R int n, num = ; scanf("%d", &n);
for (R int i = ; i <= n; ++i)
{
char opt[]; scanf("%s", opt);
if (opt[] == 'I')
{
R int x; scanf("%d", &x);
p[i] = (Opt) {, x};
}
if (opt[] == 'O')
{
R int x; scanf("%d", &x);
p[i] = (Opt) {, x};
}
if (opt[] == '?') p[i] = (Opt) {, };
}
for (R int i = ; i <= n; ++i)
{
if (p[i].type == ) continue;
if (lastt[p[i].x] == p[i].type)
{
v[last[p[i].x]].push_back(i);
}
last[p[i].x] = i;
lastt[p[i].x] = p[i].type;
}
for (R int i = ; i < v[].size(); ++i) q.push(v[][i]);
for (R int i = ; i <= n; ++i)
{
for (R int j = ; j < v[i].size(); ++j) q.push(v[i][j]);
if (p[i].type == && !q.empty())
{
R int top = q.top(); q.pop();
if (top < i) return !printf("%d\n", top);
}
}
if (q.empty()) puts("-1");
else printf("%d\n", q.top());
return ;
}

优惠劵

最新文章

  1. ASP.NET MVC 设置Area中 Controller 的方法 默认启动页
  2. SVN使用教程之-分支/标记 合并 subeclipse (转)
  3. java设计模式设计模式
  4. prior knowledge
  5. Xutils请求服务器json数据与下载文件
  6. js类型判断
  7. SqlHelper文件复习
  8. NOIP2013Day1解题报告
  9. Codeforces Round #340 (Div. 2) C. Watering Flowers 暴力
  10. NGINX开篇
  11. ruby 正则表达式 匹配规则
  12. SpaceSyntax【空间句法】之DepthMapX学习:第二篇 输出了什么东西 与 核心概念
  13. Flask-ORM-数据库的对象关系映射模型-备忘
  14. MySQL基准测试(二)--方法
  15. 实用的php清除html,php去除空格与换行,php清除空白行和换行,提取页面纯文本
  16. 树和二叉树-&gt;线索二叉树
  17. multi-head attention
  18. linux mce的一些相关内容和用户态监控的设计方法
  19. 用R理解统计学
  20. flex弹性布局学习总结

热门文章

  1. 网易Java程序员两轮面试,这些问题你能答对几个?
  2. python 安装PostgreSQL 模块:psycopg2
  3. 【Havel 定理】Degree Sequence of Graph G
  4. PB赋值粘贴
  5. SQL SERVER 相关
  6. No compiler is provided in this environment. Perhaps you are running on a JR
  7. MVC4学习要点记四
  8. centos7安装配置NFS文件共享存储
  9. powershell查看版本信息
  10. 记一次被自己DDOS攻击