CF Question Collection PART 7 #264 div 2 E_html/css_WEB-ITnose
【原题】
E. Caisa and Tree
time limit per test
10 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Caisa is now at home and his son has a simple task for him.
Given a rooted tree with n vertices, numbered from 1 to n (vertex 1 is the root). Each vertex of the tree has a value. You should answer q queries. Each query is one of the following:
You are given all the queries, help Caisa to solve the problem.
Input
The first line contains two space-separated integers n, q (1?≤?n,?q?≤?105).
The second line contains n integers a1,?a2,?...,?an (1?≤?ai?≤?2·106), where ai represent the value of node i.
Each of the next n?-?1 lines contains two integers xi and yi (1?≤?xi,?yi?≤?n; xi?≠?yi), denoting the edge of the tree between vertices xi and yi.
Each of the next q lines contains a query in the format that is given above. For each query the following inequalities hold: 1?≤?v?≤?n and 1?≤?w?≤?2·106. Note that: there are no more than 50 queries that changes the value of a vertex.
Output
For each query of the first type output the result of the query.
Sample test(s)
input
4 610 8 4 31 22 33 41 11 21 31 42 1 91 4
output
-112-11
Note
gcd(x,?y) is greatest common divisor of two integers x and y.
【分析】这道题是做现场赛的。本来能A的,但是太紧张了=而且也不会用vector,边表搞的麻烦死了。
开始看到修改操作才50次、时间又松,真是爽!估计每次可以暴力重构这颗树,然后对于每个质因子记录最优值。
首先每次不能sqrt的效率枚举一个数的因子,我们可以预处理出每个数的所有质因子。(其实有更省空间的)
剩下来要解决的问题是:因为我是用dfs的,怎么把某个子树的信息在搜完后再去掉?(以免影响其他子树)HHD表示用vector一点也不虚。其实应该也可以用边表类似的思路,但是麻烦= =
【代码】
#include#include #include #include #define N 100005#define S 2000005#define push push_back#define pop pop_backusing namespace std;vector fac[S],f[S];int data[N],ans[N],end[N],pf[S],deep[N];int C,cnt,n,Q,i,x,y,opt;struct arr{int go,next;}a[N*2];inline void add(int u,int v){a[++cnt].go=v;a[cnt].next=end[u];end[u]=cnt;}inline void init(){ int H=2000000; for (int i=2;i<=H;i++) if (!pf[i]) { for (int j=i;j<=H;j+=i) fac[j].push(i),pf[j]=1; }}void dfs(int k,int fa){ int P=data[k]; for (int i=0;i deep[ans[k]]) ans[k]=f[go][temp-1]; f[go].push(k); } for (int i=end[k];i;i=a[i].next) if (a[i].go!=fa) dfs(a[i].go,k); for (int i=0;i

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Mouse macros assign a series of complex operations to the mouse buttons, which can be simply understood as mouse shortcut key settings. After clicking the button to set the mouse macro, you can complete some operations that are usually impossible to do. So how to set mouse macros when playing CF? Let’s take a look at the cf Logitech mouse macro setting tutorial. 1. First, install the Logitech game software on your computer, and then click as shown by the arrow in the picture to open the custom button setting interface. Next, you need to select a key, such as the left key, click the small arrow, and then select "Edit Command" in the pop-up menu, so that you can open the left key macro setting interface. 3. Then click the button, as shown by the red arrow in the picture, click the text box and enter any key. Note that such as A

CSS method to realize that a div is missing a corner: 1. Create an HTML sample file and define a div; 2. Set the width and height background color for the div; 3. Add a pseudo class to the div that needs to delete a corner, and set the pseudo class to Use the same color as the background color, then rotate it 45 degrees, and then position it to the corner that needs to be removed.

Preface Recently, there is a browser script based on ChatGPTAPI on GitHub, openai-translator. In a short period of time, the star has reached 12k. In addition to supporting translation, it also supports polishing and summarizing functions. In addition to browser plug-ins, it also uses tauri packaging. If you have a desktop client, aside from the fact that tauri uses the rust part, the browser part is still relatively simple to implement. Today we will implement it manually. The interface provided by openAI, for example, we can copy the following code and initiate a request in the browser console to complete the translation //Example constOPENAI_API_KEY="s

The div box model is a model used for web page layout. It treats elements in a web page as rectangular boxes. This model contains four parts: content area, padding, border and margin. The advantage of the div box model is that it can easily control the layout of the web page and the spacing between elements. By adjusting the size of the content area, inner margin, border and outer margin, various layout effects can be achieved. The box model also provides some Properties and methods can dynamically change the style and behavior of the box through CSS and JavaScript.

The differences are: 1. div is a block-level element, and span is an inline element; 2. div will automatically occupy a line, while span will not automatically wrap; 3. div is used to wrap larger structures and layouts, and span is used to wrap Text or other inline elements; 4. div can contain other block-level elements and inline elements, and span can contain other inline elements.

The difference between iframe and div is that iframe is mainly used to introduce external content, which can load content from other websites or divide a web page into multiple areas. Each area has its own independent browsing context, while div is mainly used to divide and organize content. block for layout and style control.

Adjustment steps: 1. On the Win10 system desktop, right-click the start button and select "Settings"; 2. Click the "System" icon; 3. Click the "Display" menu item in the left sidebar; 4. Click "Display Adapter" on the right Properties" shortcut link; 5. Click the "List all modes" button; 6. Select "1024*768 True Color 60 Hz" from all modes; 7. Click the "Monitor" label above and set it to 60 Hz; 8. Click "OK" and then restart the computer.

The methods are: 1. Set the two div elements to the "float:left;" attribute; 2. Use CSS's flex layout to easily display elements side by side; 3. Use CSS's grid layout to also display elements side by side.
